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
Quote Reply
Re: [katabd] Some useful Globals In reply to
Here's another:

Generates a random character combination:

sub {
my @rand = (0 .. 9, 'a' .. 'z', 'A' .. 'Z');
my $chars = 'AT';
$chars .= $rand[rand @rand] for (1..6);
$chars .= time;
return $chars;
}

~ ERASER


Free JavaScripts @ Insight Eye
Quote Reply
Re: [katabd] Some useful Globals In reply to
Maybe you could add this as a listing in the resources section, so people can find it in the future Smile

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] Some useful Globals In reply to
Hi

That is already done.. just wanna have it in one more place for peole who do not look every where..Laugh
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Some useful Globals In reply to
Hello. I get the following error message when implementing the last searched terms global

What is missing or needs to be modified?

Thanks in advance.

mgeyman

A fatal error has occured:
Can't call method "fetchrow_hashref" on an undefined value at (eval 17) line 7.


Please enable debugging in setup for more details.Stack Trace======================================Links (9271): Links::environment called at /home/ohiobiz/linkssql2/admin/Links.pm line 418 with no arguments.Links (9271): Links::fatal called at (eval 17) line 7 with arguments (Can't call method "fetchrow_hashref" on an undefined value at (eval 17) line 7. ).Links (9271): Links::__ANON__ called at /home/ohiobiz/linkssql2/admin/GT/Template.pm line 759 with arguments (HASH(0x84c30f8)).Links (9271): GT::Template::_get_var called at /home/ohiobiz/linkssql2/admin/templates/default/compiled/rate.html.compiled line 69 with arguments (GT::Template=HASH(0x84c2fc0), last_searched, 0, 1).Links (9271): GT::Template::__ANON__ called at /home/ohiobiz/linkssql2/admin/GT/Template.pm line 539 with arguments (GT::Template=HASH(0x84c2fc0)).Links (9271): GT::Template::_parse called at /home/ohiobiz/linkssql2/admin/GT/Template.pm line 89 with arguments (GT::Template=HASH(0x84c2fc0), rate.html, HASH(0x84c2dbc)).Links (9271): GT::Template::parse called at /home/ohiobiz/linkssql2/admin/Links.pm line 291 with arguments (GT::Template, rate.html, ARRAY(0x84c2dec), HASH(0x84c2dbc)).Links (9271): Links::user_page called at (eval 10) line 1 with arguments (rate.html, HASH(0x84c1abc), HASH(0x84c2dbc)).Links (9271): Links::SiteHTML::site_html_rate called at /home/ohiobiz/linkssql2/admin/GT/Plugins.pm line 88 with arguments (HASH(0x84c1abc), [undef]).Links (9271): GT::Plugins::dispatch called at /home/ohiobiz/linkssql2/admin/Links/SiteHTML.pm line 28 with arguments (GT::Plugins, /home/ohiobiz/linkssql2/admin/Plugins, site_html_rate, *Links::SiteHTML::site_html_rate, HASH(0x84c1abc), [undef]).Links (9271): Links::SiteHTML::display called at /home/ohiobiz/linkssql2/admin/Links/User/Rate.pm line 48 with arguments (rate, HASH(0x84c1abc)).Links (9271): Links::User::Rate::handle called at /home/ohiobiz/linkssql2/admin/GT/Plugins.pm line 88 with no arguments.Links (9271): GT::Plugins::dispatch called at /home/www/pages/ohiobiz/linkssql2/rate.cgi line 25 with arguments (GT::Plugins, /home/ohiobiz/linkssql2/admin/Plugins, handle_rate, CODE(0x80d495c)).
Quote Reply
Re: [mgeyman] Some useful Globals In reply to
You have the search logger plugin installed right?
Quote Reply
Re: [Paul] Some useful Globals In reply to
Paul,

Yes, I do. Do I need to modify some code?

Mgeyman
Quote Reply
Re: [mgeyman] Some useful Globals In reply to
The only reason I can see for the error is if the SearchLog table doesn't exist or the TS column doesn't exist.

Try printing $GT::SQL::error from within your global after $db->select;
Quote Reply
Re: [Paul] Some useful Globals In reply to
Paul,

I had to make one modification to SearchLogger.pm in order for it to span the results.

mgeyman
Quote Reply
Re: [katabd] Some useful Globals In reply to
good job, am sure many ppl will enjoy these!
Quote Reply
Re: [mgeyman] Some useful Globals In reply to
Hi

I know this is a long responce.. but to be there late is better than not showing up.. (Humm.. some times).

Yes a bug must be corrected in the Search_log plug in before this global will work..

and the correction mentioned is right as far as I remember..
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Some useful Globals In reply to
I'm sorry I'm a little dense but where can I find the "fix" for the plugin so I can get the last searched terms to work properly?

Thanks.

mgeyman
Quote Reply
Re: [mgeyman] Some useful Globals In reply to
I;m almost embarrassed to ask this (because I should know ) Crazy but where do you put the global and how do you call it up?
Quote Reply
Re: [rayhne] Some useful Globals In reply to
1. Admin->Build->Template Globals

2. Cut and paste your new global into the blank box at the bottom of the list

3. Put the name of the global in the smaller blank box on its left

4. Click update

5. Try doing a search or a build on your site... if an error results, than there is something wrong with the global... take it out!

6. Put the new tag for the global into your template and build. <%globalname, $inputfunctions%>. Replace global name with the name of the global from step 3. $inputfunctions is what the global wants... like a number '12' for example.


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Aug 1, 2002, 10:10 AM
Quote Reply
Re: [Ian] Some useful Globals In reply to
I'd like to do the top searches global. I've put the global in but when I put the tag in, nothing happpens.

<%top_searches, $inputfunctions%>
Quote Reply
Re: [rayhne] Some useful Globals In reply to
It looks like the global code is wrong:

return $output > -1 ? join('-', $output): 'No terms yet!';

...should be:

return ($output || 'No terms yet!');

Im not sure why you are using this though?

<%top_searches, $inputfunctions%>

Last edited by:

Paul: Aug 1, 2002, 10:37 AM
Quote Reply
Re: [rayhne] Some useful Globals In reply to
Rayhne,

<%top_searches, $inputfunctions%>

This is just a generic example.

You have to use the actual tag for the global in question, it will be different for each one.

<%global_name, $some_variable%> is the usual the format.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Some useful Globals In reply to
The global name is top_searches....it's the some_variable that has me confused.
Quote Reply
Re: [rayhne] Some useful Globals In reply to
Just drop the some_variable, as it looks like this global does not require any input.

<%top_searches%>


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Some useful Globals In reply to
Shouldn't it be

<%topsearches($inputfunctions)%>

or am I missing something?

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Some useful Globals In reply to
No you are right, my mistake (which carried through without me picking it up!)


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [yogi] Some useful Globals In reply to
Actually, it seems to work fine with just <%top_searches%>. What would the ($inputfunctions) be?
Quote Reply
Re: [rayhne] Some useful Globals In reply to
Thats is not for the global you are using, that would be for globals which want some kind of input.

Like the tags you use in editor monitor for example, they want the editor name:

<%Plugins::EditorMonitor::EditorRewards(Username)%>

(Username) is passed into the function or global.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [katabd] Some useful Globals In reply to
Just a note that, on the information for total hits in the Resources section, the tag for total hits is incorrect. It says to use <%newlinks%>.