Gossamer Forum
Quote Reply
Some useful Globals
Hi

here is a list of some useful globals hope you will like:




1- Meta keywords: Will generate a keyword meta tag for each category by spliting its name..

sub {
my $vars = shift;
my $cat = $vars->{category_name};
$cat =~ s|/|, |g;
return $cat;
}




Meta keywords: Will generate a keyword meta tag for each category by its sub cats..

sub {
my $vars = shift;
my $categories = $vars->{category_loop};
my $cat = join(", ", map { $_->{Name} } @$categories);
return $cat;
}




Random Link:

sub {
my $db = $DB->table('Links');
my $total = $db->count ( 'isValidated' => 'Yes' );
my $rand = int( rand($total) );
$db->select_options ("LIMIT $rand, 1");
my $link = $db->select->fetchrow_hashref;
my $html = Links::SiteHTML::display('link', $link);
return $html;
}




Category list:

sub {
my $tags = shift;
my $cat_db = $DB->table('Category');
$cat_db->select_options("ORDER BY Full_Name");
my @root_cats = $cat_db->select (['Full_Name'])->fetchall_list;
my $output;
foreach my $root_cat (@root_cats) {
my $url = $cat_db->as_url($root_cat);
$output .= qq~<option value="$root_cat">$root_cat~;
}
return $output;
}




Last searched words:

sub {
my ($output,$db,$sth);
my $db = $DB->table('SearchLog');
$db->select_options ('ORDER BY TS DESC', 'LIMIT 5');
$sth = $db->select;

while (my $row = $sth->fetchrow_hashref) {
$output .= qq~*&nbsp;<a href="$CFG->{db_cgi_url}/search.cgi?query=$row->{Term}">$row->{Term}</a><br>~;
}
return $output > -1 ? join('-', $output): 'No terms yet!';

}




Newest Links:

sub {
# Displays the newest links on the home page.
my ($output,$sth,$link);
my $search_db = $DB->table('Links');
$search_db->select_options ('ORDER BY Add_Date DESC Limit 7');
$sth = $search_db->select ( { isNew => 'Yes', isValidated => 'Yes' });
while ($link = $sth->fetchrow_hashref) {
if (length $link->{Title} > 20) {
$link->{Title} = substr($link->{Title}, 0, 20) . '...';
}
$output .= Links::SiteHTML::display ('link1', $link);
}
return $output;
}




Total number of hits:

sub {
my ($total) = $DB->table('Links')->select(['SUM(Hits)'])->fetchrow_array;
return $total;
}




Top cats in a drop down menu:

sub {
my $tags = shift;
my $cat_db = $DB->table('Category');
$cat_db->select_options("ORDER BY Full_Name");
my @root_cats = $cat_db->select (['Full_Name'], { FatherID => 0 })->fetchall_list;
my $output;
foreach my $root_cat (@root_cats) {
my $url = $cat_db->as_url($root_cat);
$output .= qq~<OPTION VALUE="$CFG->{build_root_url}/$url">$root_cat~;
}
return $output;
}




Top search words:

sub {
my ($output,$db,$sth);
my $db = $DB->table('SearchLog');
$db->select_options ('ORDER BY HitCount DESC', 'LIMIT 5');
$sth = $db->select;

while (my $row = $sth->fetchrow_hashref) {
$output .= qq~*&nbsp;<a href="$CFG->{db_cgi_url}/search.cgi?query=$row->{Term}">$row->{Term}</a><br>~;
}
return $output > -1 ? join('-', $output): 'No terms yet!';

}



Enjoy
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Subject Author Views Date
Thread Some useful Globals katabd 9445 Jul 8, 2002, 10:36 PM
Post Re: [katabd] Some useful Globals
Eraser 9231 Jul 9, 2002, 2:06 AM
Thread Re: [katabd] Some useful Globals
Andy 9330 Jul 9, 2002, 2:31 AM
Post Re: [Andy] Some useful Globals
katabd 9259 Jul 9, 2002, 5:53 AM
Thread Re: [katabd] Some useful Globals
mgeyman 9155 Jul 24, 2002, 5:02 AM
Thread Re: [mgeyman] Some useful Globals
Paul 9205 Jul 24, 2002, 5:42 AM
Thread Re: [Paul] Some useful Globals
mgeyman 9147 Jul 24, 2002, 6:23 AM
Post Re: [mgeyman] Some useful Globals
Paul 9207 Jul 24, 2002, 6:26 AM
Post Re: [Paul] Some useful Globals
mgeyman 9078 Jul 24, 2002, 6:27 AM
Thread Re: [mgeyman] Some useful Globals
katabd 9218 Jul 25, 2002, 3:43 PM
Thread Re: [katabd] Some useful Globals
mgeyman 9125 Jul 25, 2002, 5:17 PM
Thread Re: [mgeyman] Some useful Globals
rayhne 9033 Aug 1, 2002, 6:47 AM
Thread Re: [rayhne] Some useful Globals
Ian 9119 Aug 1, 2002, 10:09 AM
Thread Re: [Ian] Some useful Globals
rayhne 9024 Aug 1, 2002, 10:32 AM
Post Re: [rayhne] Some useful Globals
Paul 9112 Aug 1, 2002, 10:37 AM
Thread Re: [rayhne] Some useful Globals
Ian 9079 Aug 1, 2002, 10:40 AM
Thread Re: [Ian] Some useful Globals
rayhne 8983 Aug 1, 2002, 11:57 AM
Post Re: [rayhne] Some useful Globals
Ian 9004 Aug 1, 2002, 12:05 PM
Thread Re: [Ian] Some useful Globals
yogi 9036 Aug 1, 2002, 2:11 PM
Post Re: [yogi] Some useful Globals
Ian 9047 Aug 1, 2002, 2:12 PM
Thread Re: [yogi] Some useful Globals
rayhne 9104 Aug 1, 2002, 2:35 PM
Post Re: [rayhne] Some useful Globals
Ian 9025 Aug 1, 2002, 2:43 PM
Post Re: [katabd] Some useful Globals
xpert 9175 Jul 24, 2002, 7:48 AM
Post Re: [katabd] Some useful Globals
rayhne 8922 Aug 2, 2002, 7:38 AM