Gossamer Forum
Home : Products : Others : Gossamer Community :

Globals automatically HTML escape strings when 'returning' ?

Quote Reply
Globals automatically HTML escape strings when 'returning' ?
Hi. I'm trying to write a modification to GCommunity, so we can put an online members area up on UltraNerds.

I have the following global;

Code:
sub {

my $User = shift;
my $table = $DB->table('comm_users');

my $sth = $table->select( { comm_username => $User } ) ;

while (my $hit = $sth->fetchrow_hashref) {

my @cut = split /\n/, $hit->{prof_OwnedPrograms};

my $back;
foreach (@cut) {
$back .= qq|$_ - <a href="community.cgi?do=download&file=$_">Download</a>|;
}

#$back =~ s|([^\/]+)|GT::CGI->unescape( $1 )|e;
#return GT::CGI->unescape($back);
return GT::CGI->unescape($back);

}


}

...The problem is, that it outputs it like;

Quote:
Ace_PPC - &lt;a
href=&quot;community.cgi?do=download&amp;file=Ace_PPC&quot;&gt;Download&lt;/a&gt;

....as you can see, its escaping the whole string.

If I replace;

Code:
return GT::CGI->unescape($back);

...with;

Code:
print $back;

or...

Code:
print GT::CGI->unescape($back);


Does anyone know if this is a bug, or just something stupid I'm doing? I'm pretty new with GCommunity, so this is pretty new to me. Do globals not work the same way as LinksSQL? In LSQL, you could use 'return' and it would just return whatever the string held, and not escape it? Unsure

TIA

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] Globals automatically HTML escape strings when 'returning' ? In reply to
I'm not quite sure this is just related to globals either. I tried adding the following to /lib/Community.pm;

Code:
# custom modification global!
sub OwnedPrograms {

my $User = $_[0];

my $table = $DB->table('comm_users');
$table->select_options('LIMIT 1');

my $sth = $table->select( { comm_username => $User } ) || return $GT::SQL::error;

my $back;
while (my $hit = $sth->fetchrow_hashref) {

my @cut = split /\n/, $hit->{prof_OwnedPrograms};

foreach (@cut) {
$back .= qq{$_ - <a href="community.cgi?do=download&file=$_">Download</a>};
}

}

return $back;

}

... and then called it with;

Code:
<%Community::OwnedPrograms($comm_username)%>

Anyone got any suggestions? This is really quite annoying :(

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] Globals automatically HTML escape strings when 'returning' ? In reply to
Just do

<%unescape_html your_template_tag%>

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Globals automatically HTML escape strings when 'returning' ? In reply to
Hi. That doesn't seem to work?

<%unescape_html OwnedPrograms($comm_username)%>

and

<%unescape OwnedPrograms($comm_username)%>

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] Globals automatically HTML escape strings when 'returning' ? In reply to
It's

<%unescape_html your_template_tag%>

and not

<%unescape_html your_global%>

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Globals automatically HTML escape strings when 'returning' ? In reply to
So it doesn't work with globals?

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] Globals automatically HTML escape strings when 'returning' ? In reply to
You can write your global such that it returns a hashref, as in

return { my_new_tag => '<a>something</a>' };

Then you would call your global, and unescape the new html string

<%global%>
<%unescape_html my_new_tag%>

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Globals automatically HTML escape strings when 'returning' ? In reply to
Yeah, thats pretty much what I ended up doing;

Code:
<%OwnedPrograms($comm_username)%>
<%unescape_html Owned%><br />

Code:
sub {

my $User = $_[0];

my $table = $DB->table('comm_users');
$table->select_options('LIMIT 1');

my $sth = $table->select( { comm_username => $User } ) || return $GT::SQL::error;

my $back;
while (my $hit = $sth->fetchrow_hashref) {

my @cut = split /\n/, $hit->{prof_OwnedPrograms};

foreach (@cut) {
$back .= qq{$_ - <a href="community.cgi?do=download&file=$_">Download</a>};
}

}

return { Owned => $back };

}

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] Globals automatically HTML escape strings when 'returning' ? In reply to
Hi,

All tags are HTML escaped by default now. In order to have something not html escaped, you should return a ref:

Code:
sub { my $html = "<b>some html</b>"; return \$html;
}

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Globals automatically HTML escape strings when 'returning' ? In reply to
Ah, cool. I was thinking it was more a bug, but at least its a feature :)

Is this implementation going to take effect in 2.1.3 of LSQL too

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!