News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Am I ignoring this user (on profiles page)

Started by samborabora, August 22, 2014, 10:56:53 AM

Previous topic - Next topic

samborabora

Currently I have:
if (!$context['user']['is_owner'])
echo '
<span class="profeignore">
<a href="', $scripturl, '?action=ignoreuser;u=', $context['id_member'], '">Ignore User</a></span><br />';


Under the profile. Very nice. Now, I'd like it to, preferably, be something like this:
if (!$context['user']['is_owner'] && !$context['member']['is_ignored'])
echo '
<span class="profeignore">
<a href="', $scripturl, '?action=ignoreuser;u=', $context['id_member'], '">Ignore User</a></span><br />';
if (!$context['user']['is_owner'] && $context['member']['is_ignored'])
echo '
<span class="profeignore"> <a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '">Unignore User</a></span><br />
';


But, that didn't work. So, I tried:
if (!$context['user']['is_owner'] && !$context['user']['is_ignored'])
echo '
<span class="profeignore">
<a href="', $scripturl, '?action=ignoreuser;u=', $context['id_member'], '">Ignore User</a></span><br />';
if (!$context['user']['is_owner'] && $context['user']['is_ignored'])
echo '
<span class="profeignore"> <a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '">Unignore User</a></span><br />
';


Neither. So, how do I test that I am ignoring a user from their profile page?

Hj Ahmad Rasyid Hj Ismail

I kinda don't understand your code that much. Have you created this context before even using it: $context['member']['is_ignored'])? I can't seem to find it in any of the profile source or template files. So I guess that is why it is not working?


samborabora

Yes, ufnortunatly it was hypothetical code! I noticed there's no [is_ignored] function in the members array, so what's the long-hand way of checking if I have the member who's profile I'm viewing on ignore? I think it can be checked against the users database tables, can't it?

Hj Ahmad Rasyid Hj Ismail

Sorry, but I normally use available code in SMF. If there isn't one, I will look at any mod for SMF. Other than that, I am too lazy to learn how to create one. :)

Arantor

Well, you're dealing with - presumably - $_GET['u'] as the user id whose profile you're looking at?

if (in_array($_GET['u'], $user_info['ignoreusers']))
{
  // things to do if the user is being ignored by the current user
}

samborabora

Quote from: ‽ on August 22, 2014, 11:54:29 AM
Well, you're dealing with - presumably - $_GET['u'] as the user id whose profile you're looking at?

if (in_array($_GET['u'], $user_info['ignoreusers']))
{
  // things to do if the user is being ignored by the current user
}


Thanks arantor, what's the inverse of this, ie: if I am not ignoring the user, so I can use that to display the ignore button. !empty(in_array($_GET['u'], $user_info['ignoreusers']) ?

Arantor

No... just a simple !

if (!in_array($_GET['u'], $user_info['ignoreusers']))
{
  // things to do if the user is being ignored by the current user
}

samborabora

Quote from: ‽ on August 22, 2014, 11:59:07 AM
No... just a simple !

if (!in_array($_GET['u'], $user_info['ignoreusers']))
{
  // things to do if the user is being ignored by the current user
}


Lol, just needed to get that syntax right ;) Tried this:

if (!$context['user']['is_owner']){
if (in_array($_GET['u'], $user_info['ignoreusers']))
{
echo '
<span class="profeignore">
<a href="', $scripturl, '?action=ignoreuser;u=', $context['id_member'], '">Ignore User</a></span><br />';
}
if (in_array($_GET['u'], $user_info['ignoreusers']))
{
echo '
<span class="profeignore"> <a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '">Unignore User</a></span><br />
';
}
}


Should work, but not seeing the unignore come alive when I ignore the user?

Arantor

That's because both if statements are the same.

You can however just have:
if (!$context['user']['is_owner']){
if (!in_array($_GET['u'], $user_info['ignoreusers']))
{
echo '
<span class="profeignore">
<a href="', $scripturl, '?action=ignoreuser;u=', $context['id_member'], '">Ignore User</a></span><br />';
}
else
{
echo '
<span class="profeignore"> <a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '">Unignore User</a></span><br />
';
}
}

samborabora

Quote from: ‽ on August 22, 2014, 12:18:24 PM
That's because both if statements are the same.

You can however just have:
if (!$context['user']['is_owner']){
if (!in_array($_GET['u'], $user_info['ignoreusers']))
{
echo '
<span class="profeignore">
<a href="', $scripturl, '?action=ignoreuser;u=', $context['id_member'], '">Ignore User</a></span><br />';
}
else
{
echo '
<span class="profeignore"> <a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '">Unignore User</a></span><br />
';
}
}


Hmm, tried that, and crosschecked that the users are appearing in my ignore list, and they are, except it is still showing an ignore link, not an unignore link?

Arantor

Well the code says 'if the supplied user is not on my ignore list, show the ignore link'. That would imply $user_info is not defined as a global in your template.

samborabora

Quote from: ‽ on August 22, 2014, 12:24:41 PM
Well the code says 'if the supplied user is not on my ignore list, show the ignore link'. That would imply $user_info is not defined as a global in your template.

I'm assuming that in_array($_GET['u'] is getting the member from the profile? This is going on profile.template, so the proposed member it's checking against would be the current user's profile I'm checking, is that what this looks for?

Arantor

Well... $_GET['u'] means get the ;u= parameter from the URL. Since I had no idea how you were using this, I had no better clue as to what to suggest.

It's then comparing it to the current user's ignore list, so if you are ignoring user id 2 and you go to action=profile;u=2, $_GET['u'] is 2, to be compared against your ignore list.

Then again I'm aware you're going through and rewriting the profile area, so to be honest, all bets are kind of off anyway...

samborabora

Quote from: ‽ on August 22, 2014, 12:28:26 PM
Well... $_GET['u'] means get the ;u= parameter from the URL. Since I had no idea how you were using this, I had no better clue as to what to suggest.

It's then comparing it to the current user's ignore list, so if you are ignoring user id 2 and you go to action=profile;u=2, $_GET['u'] is 2, to be compared against your ignore list.

Then again I'm aware you're going through and rewriting the profile area, so to be honest, all bets are kind of off anyway...

Yeah, that's right, and it looks good, I agree with you, it should work. I haven't actually done rewriting to the degree where standard stuff isn't working, so this should work fine and dandy. I think I still, unfortunatly, have that stupid friendly URLs on, but that hasn't actually, believe it not, caused a problem so far, since the link still looks like "profile/?u=330" jsut can't figure out why it wouldn't be working?

Arantor

Well, you can use $context['id_member'] instead of $_GET['u'] if that's any help.

But I still wonder if you have $user_info in scope.

samborabora

Quote from: ‽ on August 22, 2014, 12:36:38 PM
Well, you can use $context['id_member'] instead of $_GET['u'] if that's any help.

But I still wonder if you have $user_info in scope.
if (!$context['user']['is_owner']){
if (!in_array($context['id_member'], $user_info['ignoreusers']))
{
echo '
<span class="profeignore">
<a href="', $scripturl, '?action=ignoreuser;u=', $context['id_member'], '">Ignore User</a></span><br />';
}
else
{
echo '
<span class="profeignore">
<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '">Unignore User</a></span><br />
';
}
}


Still not displaying any change, in Load.php I have:
// Set up the $user_info array.
$user_info += array(


So, it should be present? I haven't reworking this part of the profile too much, it's just in the standard template.

Hj Ahmad Rasyid Hj Ismail

I think he means global $user_info; ? You can simply add it before your if statement if you are not sure about it.

Arantor

Yes, that's what I mean, you have to declare in the template that you want to access the variable from outside the local scope.

samborabora

Quote from: ahrasis on August 22, 2014, 12:49:17 PM
I think he means global $user_info; ? You can simply add it before your if statement if you are not sure about it.

Not seeing global $user_info in profile_view, is that where it should be? How should I place it before the final statement?

Arantor

You need to globalise it in whichever function you are trying to use it, before you try to use it.

Advertisement: