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

What does these Globals do & how to call them on pages

Quote Reply
What does these Globals do & how to call them on pages

I have below Globals in my list & need to use few of them, but can't really distinguish one from another & don't recall how to use them :(.. Please help..

Global Name + Codes:
-----------------------------------------------------------------
cat_all_properties
Code:
sub {
my $ID = $IN->param('ID') || return '';
my $cat = $DB->table('Category')->select( { ID => $ID } )->fetchrow_hashref;
return $cat;
}
-----------------------------------------------------------------
cat_field
Code:
sub {
my $cols = $DB->table('Category')->cols;
my $return; foreach (sort{$cols->{$a}->{pos} <=> $cols->{$b}->{pos}} keys %$cols){ my $f = $cols->{$_};
my $n = $f->{form_display} || $_;
my $field = "Link_Add_Description" . $f;
$return->{$field} = qq|$n - Example, $f->{default}|;
} return $return;
}

-----------------------------------------------------------------
user_prop_on_any_page
Code:
sub {
my $User= $_[0];
my $Field= $_[1];
my $table = $DB->table('Users');
my $sth = $table->select( { Username => $User } );
my $Name;
while (my $hit = $sth->fetchrow_hashref) {
$Name = $hit->{$Field};
}
$Name ? return $Name : return "None";
}

-----------------------------------------------------------------
display_all_link_info
Code:
sub {
my $id=shift;
my $table = $DB->table('Links');
my $link = $table->select({ID=>$id})->fetchrow_hashref;
return {%$link};
}


-----------------------------------------------------------------
call_detail_url
Code:
sub {
my $id=shift;
my $table = $DB->table('Links');
my $link = $table->select({ID=>$id})->fetchrow_hashref;
my $detailed = $DB->table('Links')->detailed_url($id);
$link->{detailed_url} = "$CFG->{build_detail_url}/$detailed";
return {%$link};
}
-----------------------------------------------------------------

I normally name globals based on their usage, so the name of each global suggests that it does, however I can't figure out:
1: What type of output they produce.
2: How to call them.
3: What pages the output would work.

-----------------------------------------------------------------

P.S. As I am writing this post, I feel that it sounds more like something out of a video game, where there is a puzzle of old method/routine to solve before moving on to next step.


Please help....

Vishal
-------------------------------------------------------

Last edited by:

VishalT: Jan 6, 2020, 3:39 PM
Quote Reply
Re: [VishalT] What does these Globals do & how to call them on pages In reply to
I think I found the answer for two of the globals:

When used as below:

<%Links::Utils::load_reviews($ID, $detailed_max_reviews)~%>
<%all_link_info($ID)%>
<%call_detail_url%>

They work with PageCreator Plugin (another one of Andy's Plugin) on additional pages. However, still am not able to recall how to use the others & their possible outputs..

Vishal
-------------------------------------------------------
Quote Reply
Re: [VishalT] What does these Globals do & how to call them on pages In reply to
Hi,

This is why putting in comments in the globals (with examples), is always good =)

Quote:
cat_all_properties

This one gets the category based on an ID passed in via the page.cgi?ID=1234 param. So you would probably use it on a custom page where you want to load a category into it

Quote:
cat_field

It helps if the global is formatted properly :) (not random new lines starting on other lines). I've reformatted it:

Code:
sub {
my $cols = $DB->table('Category')->cols;
my $return;
foreach (sort{$cols->{$a}->{pos} <=> $cols->{$b}->{pos}} keys %$cols) {
my $f = $cols->{$_};
my $n = $f->{form_display} || $_;
my $field = "Link_Add_Description" . $f;
$return->{$field} = qq|$n - Example, $f->{default}|;
}
return $return;
}

What it seems to do is go through each of the category columns, and then pass based new tags to the template with the format:

Code:
Link_Add_Description_XXXX

This is then filled with:

$n - Example, $f->{default}

It would probably be better to also tweak it as well:

Code:
sub {
my $cols = $DB->table('Category')->cols;
my $return;
foreach (sort{$cols->{$a}->{pos} <=> $cols->{$b}->{pos}} keys %$cols) {
my $f = $cols->{$_};
if ($f->{default}) {
my $n = $f->{form_display} || $_;
my $field = "Link_Add_Description" . $f;
$return->{$field} = qq|$n - Example, $f->{default}|;
}
}
return $return;
}

Quote:
user_prop_on_any_page

This one just grabs a value from a given user. If you are trying to show it for the CURRENT logged in user, you just use <%user.FIELD_NAME%> . I guess the global you gave could be useful if you are trying to load a value from the $LinkOwner of a link though. You could really do it much cleaner with:

Code:
sub {
return $DB->table('Users')->select( [$_[1]],{ Username => $_[0] } )->fetchrow || "None";
}

Quote:
display_all_link_info

This one just grabs a link. You could do it much cleaner with:

Code:
sub {
return $DB->table('Links')->get ( { ID => $_[0] )->fetchrow_hashref || {}
}

OR use my Load_Link() function in ULTRAGlobal (check out the Readme file for instructions, as its been a while)

Quote:
call_detail_url

With ths one, see my comment above. Basically the Load_Link() function in ULTRAGlobals does all of this for you (and a few other bits).

Cheers

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] What does these Globals do & how to call them on pages In reply to
------------------------------------
This is why putting in comments in the globals (with examples), is always good =)
------------------------------------
I have organized most GLinks realated things in folder on my computer, however yeah I totally agree with you.. having a comment within the global does seem like the best and most effecient idea. Now all my globals will be set that way.. thanks.

About ULTRAGlobals.
Right now I am actually working on making a list of few Globals that I have used in the past & available features/options in Ultraglobals. I am having to reread lot of things just to understand what many of the Globals and code does. But yes, I did setup UltraGlobal so I can test all of it features too.

Thanks again.. really appreciate all the help.

Vishal
-------------------------------------------------------