Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Days_Old tag.

Quote Reply
Days_Old tag.
If anyone is interested I have written the Days_Old tag back into Links-SQL 2.0. If anyone wants the mod let me Know and I will post it here.

Quote Reply
Re: Days_Old tag. In reply to
I sure would like that. One less obstacle for me to tackle.


Dan Oakeson
http://www.AssociateCash.com
Quote Reply
Re: Days_Old tag. In reply to
Here is the code to add the Days_Old field.
The changes are to Links/SiteHTML.pm.

The added code is between the # ---------- markers.

package Links::SiteHTML;
# ==================================================================
use strict;
use Links qw/$DB $CFG/;
use GT::Plugins;
# ----- added module ---------
use GT::Date;
# ---------------------------

sub site_html_link {
# --------------------------------------------------------
# Format a single link.
#
my $rec = shift;

# Convert the date formats.
if ($CFG->{date_db_format} ne $CFG->{date_user_format}) {
Links::init_date();
# ------------- added line to preserve Add_Date from Links table row -------------
$rec->{Add_Date1} = $rec->{Add_Date};
# --------------------------------------------------------------------------------
$rec->{Add_Date} = GT::Date::date_transform ($rec->{Add_Date}, $CFG->{date_db_format}, $CFG->{date_user_format});
$rec->{Mod_Date} = GT::Date::date_transform ($rec->{Mod_Date}, $CFG->{date_db_format}, $CFG->{date_user_format});
}

# Set new and pop to either 1 or undef for templates.
(defined $rec->{'isNew'} and ($rec->{'isNew'} eq 'Yes')) ? ($rec->{'isNew'} = 1) : ($rec->{'isNew'} = 0);
(defined $rec->{'isChanged'} and ($rec->{'isChanged'} eq 'Yes')) ? ($rec->{'isChanged'} = 1) : ($rec->{'isChanged'} = 0);
(defined $rec->{'isPopular'} and ($rec->{'isPopular'} eq 'Yes')) ? ($rec->{'isPopular'} = 1) : ($rec->{'isPopular'} = 0);
(defined $Links::USER->{Username} and ($rec->{'LinkOwner'} eq $Links::USER->{Username})) ?
($rec->{'isLinkOwner'} = 1) : ($rec->{'isLinkOwner'} = 0);

# ---------------- Links Days_Old calculate ----------------------------
# Figure out how many days old it is if it's a new link.
if ($rec->{'isNew'} eq '1') {
$rec->{'Days_Old'} = &GT::Date::date_diff (&GT::Date::date_get(), $rec->{'Add_Date1'});
}
else { $rec->{'Days_Old'} = ''; }
# ----------------------------------------------------------------------

# Set the detailed_url.
$rec->{detailed_url} = "$CFG->{build_detail_url}/${$rec}{'ID'}$CFG->{build_extension}";

# Parse the template.
my $output = Links::load_template ('link.html', $rec, 0);
return $output;
}


sub site_html_print_cat {
# --------------------------------------------------------
# This routine prints out a list of categories.
#
my $subcat = shift;

my ($output, $category_name, $category_url, $i, $cat, $cat_r, @subnames);
my $parent_cat = shift @$subcat;

my $breakpoint = int (($#{$subcat}+1) / $CFG->{build_category_columns}) + ( (($#{$subcat}+1) % $CFG->{build_category_columns}) ? 1 : 0);

# Print Header.
my $table_head = $CFG->{build_category_table} || '';
my $width = int (100 / $CFG->{build_category_columns});
if ($CFG->{build_category_columns}) {
$output = qq|<div class="margin"><table $table_head><tr><td class="catlist" width="$width%" valign="top">\n|;
}
$i = 0;
my $cat_db = $DB->table('Category');

foreach $cat_r (@$subcat) {
# Get the URL and the Category name.
$category_url = $CFG->{build_root_url} . "/" . $cat_db->as_url ($cat_r->{Full_Name}) . "/" . $CFG->{build_index};
($cat_r->{Name} =~ m,.*/([^/]+)$,) ? ($category_name = $1) : ($category_name = $cat_r->{Name});
$cat_r->{Short_Name} = $category_name;
$cat_r->{URL} = $category_url;

# ------------------------ Category Days_Old Routine --------------------------
# Calculate the number of days old.
if ($cat_r->{'Has_New_Links'}) {
$cat_r->{'Days_Old'} = &GT::Date::date_diff (&GT::Date::date_get(), $cat_r->{'Newest_Link'});
}
else { $cat_r->{'Days_Old'} = ''; }
# ----------------------------------------------------------------------------

# Append @ if we are using Yahoo style cats, and it is related.


Quote Reply
Re: Days_Old tag. In reply to
How would we go about making this into a plugin, or is it even possible to do?

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: Days_Old tag. In reply to
From my reading on plugins they are able to gain control at existing pre-defined hook points in the code. I do not think that would work for this mod as there are not any plugin hooks in the area where I added the code. Perhaps Alex or someone more familiar with the plugin system can comment on this?

Quote Reply
Re: Days_Old tag. In reply to
There is actually a plugin hook for every site_html_something subroutine, its just a matter of whether its a pre or post hook, etc.

I'll take a look at it tonight.

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: Days_Old tag. In reply to
ok, I about have this plugin done, except I'm hitting a problem.

This subroutine is called as a PRE hook for site_html_link:


sub link {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'site_html_link'
# is run. You should return STOP if you don't want
# the regular code to run, or CONTINUE if you want
# the regular code to run.
#

my $link = shift;


# ------------- added line to preserve Add_Date from Links table row -------------
$link->{Add_Date1} = $link->{Add_Date} ;

# --------------------------------------------------------------------------------

# ---------------- Links Days_Old calculate ----------------------------
# Figure out how many days old it is if it's a new link.
if ($link->{'isNew'} eq '1') {
$link->{'Days_Old'} = >::Date::date_diff (>::Date::date_get(), $link->{'Add_Date1'});
}
else { $link->{'Days_Old'} = ''; }
# ----------------------------------------------------------------------

return $link;

}

But I'm when I display a link, I get:
Unknown tag: Days_Old

Could anyone please elaborate?

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: Days_Old tag. In reply to
I know this sounds trite, but make sure the plug-in installed properly. Check the plug-in.cfg file.

If not, send me the tarball and I'll take a look at it (the plugins are great that way! :)

PUGDOGŪ
PUGDOGŪ Enterprises, Inc.
FAQ: http://LinkSQL.com/FAQ


Quote Reply
Re: Days_Old tag. In reply to
I finally got it working, after fixing some perl bugs :)

If anyone wants this plugin, just ask.

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: Days_Old tag. In reply to
If you want to send it to me, I can review it and put it up on the site.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Days_Old tag. In reply to
I'm going to add some more features to it, such as some images, and an About section with the tags needed.

Since I don't have to be at school until 10 tomorrow, I should wrap this up early tomorrow.

I'll send it to you Alex the moment I'm done. Smile

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: Days_Old tag. In reply to
Problem.

See this code:

sub site_html_print_cat {
# --------------------------------------------------------
# This routine prints out a list of categories.
#
my $subcat = shift;

my ($output, $category_name, $category_url, $i, $cat, $cat_r, @subnames);
my $parent_cat = shift @$subcat;

my $breakpoint = int (($#{$subcat}+1) / $CFG->{build_category_columns}) + ( (($#{$subcat}+1) % $CFG->{build_category_columns}) ? 1 : 0);

# Print Header.
my $table_head = $CFG->{build_category_table} || '';
my $width = int (100 / $CFG->{build_category_columns});
if ($CFG->{build_category_columns}) {
$output = qq|<div class="margin"><table $table_head><tr><td class="catlist" width="$width%" valign="top">\n|;
}
$i = 0;
my $cat_db = $DB->table('Category');

foreach $cat_r (@$subcat) {
# Get the URL and the Category name.
$category_url = $CFG->{build_root_url} . "/" . $cat_db->as_url ($cat_r->{Full_Name}) . "/" . $CFG->{build_index};
($cat_r->{Name} =~ m,.*/([^/]+)$,) ? ($category_name = $1) : ($category_name = $cat_r->{Name});
$cat_r->{Short_Name} = $category_name;
$cat_r->{URL} = $category_url;

# ------------------------ Category Days_Old Routine --------------------------
# Calculate the number of days old.
if ($cat_r->{'Has_New_Links'}) {
$cat_r->{'Days_Old'} = >::Date::date_diff (>::Date::date_get(), $cat_r->{'Newest_Link'});
}
else { $cat_r->{'Days_Old'} = ''; }
# ----------------------------------------------------------------------------

See the Days_Old routine, is there a hook here anywhere I can use? I don't think I can port this part into the plugin because the $cat_r variable originates in the foreach loop.

Anyone have any input?

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: Days_Old tag. In reply to
Hi,

No, use the site_html_print_cat hook. Look at how YahooSubcats works, you are doing almost the same thing.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Days_Old tag. In reply to
Thanks Alex.
It's fully working now.
I just sent it to you.
Enjoy!


Robert Blackstone
Webmaster of Scato Search
http://www.scato.com