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

Changing Return Value for Profile Pic Global

Quote Reply
Changing Return Value for Profile Pic Global
Hey guys,

Looking for a bit of help here with some basic Perl in the globals.

We're busy redoing our comment system's layout and requires us to use a placeholder image as an avatar for users who do not have a profile picture set.

However, the way the global is set up - when there is no picture in the profile, it returns an empty value - as opposed to a null value.

This means that we're unable to do an <%if uiPhoto%>.

So we're thinking that we need to change it so that the global returns a default value (Image URL) when it finds no profile picture for that particular user.

Here's the global:

Code:
sub {
my $username = shift;
my $size = shift;
use lib ('/home/site/site.com/cgi-bin/forum/admin');

my $DB = GT::SQL->new('/home/site/site.com/cgi-bin/forum/admin/defs');
my $sth = $DB->table('User')->do_query(qq|
SELECT * FROM forum_User
WHERE user_icon IS NOT NULL
AND profile_picture_index != 0
AND user_username = "$username";
|);

my $out;
my ( @UserInfo );
my $hits = 0;
while (my $res = $sth->fetchrow_hashref()) {

my $username = $res->{user_username};
my $pic = $res->{profile_picture_index};
if($pic == 0)
{
next;
}
$hits++;
my $rows = $DB->table('Profile_Pictures')->do_query(qq|
SELECT picture$pic|.qq|_$size FROM forum_Profile_Pictures
WHERE user_id = $res->{user_id};
|);

my $row = $rows->fetchrow_arrayref();
my $picLink = qq|/graphics/forum/users/profile_pictures/$row->[0]|;

push(@UserInfo, { 'uiUsername' => $username,
'uiPhoto' => $picLink,
},
);
}

return {UserInfoLoop => \@UserInfo,
UserInfoHits => $hits,
};

}
Thanks!
Quote Reply
Re: [meso] Changing Return Value for Profile Pic Global In reply to
Hi,

You could try:

Code:
'uiPhoto' => $picLink || null

Cheers1

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] Changing Return Value for Profile Pic Global In reply to
Thanks for the response Andy,

Adding that to the global returns the following error:

Code:
Unable to compile 'get_user_profile_pic': Bareword "null" not allowed while "strict subs" in use at (eval 3434) line 34.
Quote Reply
Re: [meso] Changing Return Value for Profile Pic Global In reply to
Sorry, too many programming language going through my head <G> It should be undef

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] Changing Return Value for Profile Pic Global In reply to
 
Resolved the error, but still no luck on getting it to display correctly.

I've done a dump on the page and the field where value is set still seems to pull through an empty value.


Code:
UserInfoLoop: [];

Here's what the template looks like:

Code:
<a href="/cgi-bin/forum/gforum.cgi?username=<%GB_Comment_Name%>;">

<%get_user_profile_pic($GB_Comment_Name,'small')%>
<%loop UserInfoLoop%>
<img class="thumbs src="<%uiPhoto%>" align="left" width="50" alt="<%uiUsername%>" height="50"/></a>

<!--PRINT TEST-->
<%if uiPhoto%>YES<%else%>NO<%endif%>
<!--PRINT TEST END-->
<%endloop%>

When I use that code, including the print test at the bottom, it prints the 'YES' on areas where there is a profile picture. But it doesn't print a NO for the ones without an image.

I then tried checking if the uiPhoto eq 'undef' (not sure if the undef is supposed to be returned as a string, but I tried that). Shows 'NO' for the comments with an avatar, but again displays nothing for the cases where there isn't one.
Quote Reply
Re: [meso] Changing Return Value for Profile Pic Global In reply to
Hi,

Try printing out <%uiPhoto%>, to see what it contains. It may have a value in that you're not expecting.

Also, it may be worth doing a dump of the values being passed back, using Date::Dumper;

Code:
use Data::Dumper;
print $IN->header;
print Dumper(@UserInfo);
return {
UserInfoLoop => \@UserInfo,
UserInfoHits => $hits,
};

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] Changing Return Value for Profile Pic Global In reply to
Hi,

The way i see it @UserInfo will be empty for that user because of this:

Code:
my $pic = $res->{profile_picture_index};
if($pic == 0)
{
next;
}

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Changing Return Value for Profile Pic Global In reply to
Good point :) Probably want something more like:

Code:
if ($pic == 0) {
push @UserInfo, { 'uiUsername' => $username, 'uiPhoto' => undef };
next;
}

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!

Last edited by:

Andy: May 27, 2014, 5:46 AM
Quote Reply
Re: [Andy] Changing Return Value for Profile Pic Global In reply to
Printing <%uiPhoto%> returns a URL string for the image, as it should - on comments with avatars.

For those without though, it prints nothing. Unsure

It seems that it returns the correct values when there is an image, but as soon as there isn't a profile picture attached it continues to return an empty (not null) value of some sort. In theory if it returned a true null value for that uiPhoto, we should be able to effectively use the if/else statements.

This is all happening within that loop, and my suspicion is that at some point when it finds there is no profile picture - it just skips all the data in that global, for that particular comment, until it loops to a comment with an avatar. At least that's my assumption.
Quote Reply
Re: [meso] Changing Return Value for Profile Pic Global In reply to
Hi,

Check out Boris and my replies above :) Hopefully that'll help

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: [meso] Changing Return Value for Profile Pic Global In reply to
What Andy said WILL work, although the global as a whole looks a bit weird to me Unimpressed

These sql queries need some love :)

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Changing Return Value for Profile Pic Global In reply to
Thanks for your responses guys... I've updated the global as suggested, to:

Code:
sub {
my $username = shift;
my $size = shift;
use lib ('/home/dropzone/dropzone.com/cgi-bin/forum/admin');

my $DB = GT::SQL->new('/home/dropzone/dropzone.com/cgi-bin/forum/admin/defs');
my $sth = $DB->table('User')->do_query(qq|
SELECT * FROM forum_User
WHERE user_icon IS NOT NULL
AND profile_picture_index != 0
AND user_username = "$username";
|);

my $out;
my ( @UserInfo );
my $hits = 0;
while (my $res = $sth->fetchrow_hashref()) {

my $username = $res->{user_username};
my $pic = $res->{profile_picture_index};

if ($pic == 0) {
push @UserInfo, { 'uiUsername' => $username, 'uiPhoto' => undef};
next;
}

$hits++;
my $rows = $DB->table('Profile_Pictures')->do_query(qq|
SELECT picture$pic|.qq|_$size FROM forum_Profile_Pictures
WHERE user_id = $res->{user_id};
|);

my $row = $rows->fetchrow_arrayref();
my $picLink = qq|/graphics/forum/users/profile_pictures/$row->[0]|;

push(@UserInfo, { 'uiUsername' => $username,
'uiPhoto' => $picLink,
},
);
}

return {UserInfoLoop => \@UserInfo,
UserInfoHits => $hits,
};
}

But I'm still not having any luck...

With that global I'm still finding that the value "UserInfoLoop" in the dump is showing empty, as it was before. Furthermore all simple logic tests are not providing any result, again as has been the problem.

The values should be parsed through Userinfoloop, and ideally we would be seeing something like:

Code:
UserInfoLoop [
{
'uiPhoto' => '.../forum/users/profile_pictures/12465_GTTemp0510_small',
'uiUsername' => 'elightle'
}
];

As is seen on the comments with avatars.

However, this is still the result for comments with no avatar

Code:
UserInfoLoop[];




Quote Reply
Re: [meso] Changing Return Value for Profile Pic Global In reply to
Oh well shame on me missed this one in the first SQL query:

Code:
AND profile_picture_index != 0

if it's there users with 'profile_picture_index' eq '0' will never be selected which makes this part:

Code:
if ($pic == 0) {
push @UserInfo, { 'uiUsername' => $username, 'uiPhoto' => undef};
next;
}

practically useless :\

Try removing the SQL in question and give it another go!

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Quote Reply
Re: [eupos] Changing Return Value for Profile Pic Global In reply to
Excellent! That did the trick. Thanks a lot guys Laugh
Quote Reply
Re: [meso] Changing Return Value for Profile Pic Global In reply to
Wink

Cheers,
Boris

Facebook, Twitter and Google+ Auth for GLinks and GCommunity | reCAPTCHA for GLinks | Free GLinks Plugins
Post deleted by el noe In reply to