Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: samborabora on August 22, 2014, 10:56:53 AM

Title: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 10:56:53 AM
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?
Title: Re: Am I ignoring this user (on profiles page)
Post by: Hj Ahmad Rasyid Hj Ismail on August 22, 2014, 11:30:08 AM
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?

Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 11:50:22 AM
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?
Title: Re: Am I ignoring this user (on profiles page)
Post by: Hj Ahmad Rasyid Hj Ismail on August 22, 2014, 11:52:36 AM
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. :)
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor 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
}
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 11:58:29 AM
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']) ?
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor 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
}
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 12:12:01 PM
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?
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor 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 />
';
}
}
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 12:22:47 PM
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?
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor 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.
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 12:26:31 PM
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?
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor 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...
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 12:33:38 PM
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?
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor 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.
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 12:41:04 PM
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.
Title: Re: Am I ignoring this user (on profiles page)
Post by: Hj Ahmad Rasyid Hj Ismail 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.
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor on August 22, 2014, 01:02:47 PM
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.
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 01:07:01 PM
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?
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor on August 22, 2014, 01:07:58 PM
You need to globalise it in whichever function you are trying to use it, before you try to use it.
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 01:27:41 PM
Quote from: ‽ on August 22, 2014, 01:07:58 PM
You need to globalise it in whichever function you are trying to use it, before you try to use it.

Yep, it's going to be when I'm viewing a members profile, so it's in:

Profile-View.php
function summary($memID)
{
global $context, $memberContext, $txt, $modSettings, $user_info, $user_profile, $sourcedir, $scripturl, $smcFunc;


This follow/unfollow code just needs to be on anyones profile summary page taht isn't mine (hence the check if the user owner).

if (!in_array($context['id_member'], $user_info['ignoreusers']))

Would that be another way to test?
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 02:09:18 PM
Hmm, you're right, I get:

8: Undefined variable: user_info

and:

2: in_array() expects parameter 2 to be array, null given

Which is strange, as I'm sure user_info is in the global? Can I load it into the template before the ignore section?
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor on August 22, 2014, 02:10:30 PM
Are you modifying the summary template or some other template? You have to declare global in *each* template you want to use it in.
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 02:12:45 PM
Aha! Now this works! I just did:

function template_summary()
{
global $context, $settings, $options, $scripturl, $modSettings, $txt;


and added:
function template_summary()
{
global $context, $user_info, $settings, $options, $scripturl, $modSettings, $txt;


Which is great, but apparently, this link:
<a href="', $scripturl, '?action=profile;u=', $context['id_member'], ';area=lists;sa=ignore;remove=', $member['id'], ';', $context['session_var'], '=', $context['session_id'], '">

Isn't functional. Looks okay to me? Can see why this shouldn't work on the profile page?
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor on August 22, 2014, 02:15:38 PM
The link's wrong. It needs to point back to *your* profile because it's your ignore list that's being changed. And it is the profile of the person that you're looking at as the person you're removing from the URL.

<a href="', $scripturl, '?action=profile;u=', $user_info['id'], ';area=lists;sa=ignore;remove=', $context['member_id'], ';', $context['session_var'], '=', $context['session_id'], '">
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 02:21:53 PM
Quote from: ‽ on August 22, 2014, 02:15:38 PM
The link's wrong. It needs to point back to *your* profile because it's your ignore list that's being changed. And it is the profile of the person that you're looking at as the person you're removing from the URL.

<a href="', $scripturl, '?action=profile;u=', $user_info['id'], ';area=lists;sa=ignore;remove=', $context['member_id'], ';', $context['session_var'], '=', $context['session_id'], '">

Almost! This works:
<a href="', $scripturl, '?action=profile;area=lists;sa=ignore;remove=', $context['id_member'], ';', $context['session_var'], '=', $context['session_id'], '">

Now then, for the final trick! I would adore it if it could redirect back to the profile page instead of going to the ignore list. This would be the absolute icing on the cake and I'll die happy (until the next ridiculous mod :p ) So, how can I have it go back to the profile I'm viewing after clicking unignore?
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor on August 22, 2014, 02:28:05 PM
Profile-Modify.php

// Removing a member from the ignore list?
if (isset($_GET['remove']))
{
checkSession('get');

// Heh, I'm lazy, do it the easy way...
foreach ($ignoreArray as $key => $id_remove)
if ($id_remove == (int) $_GET['remove'])
unset($ignoreArray[$key]);

// Make the changes.
$user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray);
updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list']));

// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
redirectexit('action=profile;area=lists;sa=ignore;u=' . $memID);
}


Change the redirectexit to:
if ((int) $_GET['remove'] > 0)
redirectexit('action=profile;u=' . ((int) $_GET['remove']));
else
redirectexit('action=profile');


That'll fix removing a user from redirection, can't vouch for the add-to-ignore list since that's not a standard function. I seem to recall making a mod for it years ago but I don't remember. But similer sort of deal, you'd find the redirectexit call in it and change it to point to the user id that you've added rather than the user's own.
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 22, 2014, 02:34:21 PM
WOW!!!! That works!!!

// Removing a member from the ignore list?
if (isset($_GET['remove']))
{
checkSession('get');

// Heh, I'm lazy, do it the easy way...
foreach ($ignoreArray as $key => $id_remove)
if ($id_remove == (int) $_GET['remove'])
unset($ignoreArray[$key]);

// Make the changes.
$user_profile[$memID]['pm_ignore_list'] = implode(',', $ignoreArray);
updateMemberData($memID, array('pm_ignore_list' => $user_profile[$memID]['pm_ignore_list']));

// Redirect off the page because we don't like all this ugly query stuff to stick in the history.
if ((int) $_GET['remove'] > 0)
redirectexit('action=profile;u=' . ((int) $_GET['remove']));
else
redirectexit('action=profile');
}


I am SOOOO incredibly grateful to you guys for ALL of your help, thank you SO MUCH!! :D :D

(as you can tell, when something works I experience euphoria, and this is why i love SMF coding as a hobby :D )
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor on August 22, 2014, 02:36:08 PM
I know that euphoria - it's why I'm still here after 5 years.
Title: Re: Am I ignoring this user (on profiles page)
Post by: Hj Ahmad Rasyid Hj Ismail on August 23, 2014, 12:19:29 AM
Congratulations again. You are now in good hand I suppose. :)
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 23, 2014, 12:52:28 AM
Quote from: ahrasis on August 23, 2014, 12:19:29 AM
Congratulations again. You are now in good hand I suppose. :)

It's amazing, I feel truly lucky to be in the company of such experienced geniuses, all of you ;) Believe it or not, everything I've set out to do so far has actually happened and there's only a few ideas left to get right, after a year of fiddling! :D
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor on August 23, 2014, 12:56:07 AM
The real secret is putting in the effort to make some sense of what's going on. The only difference between you and me is that I've just been doing it longer.

If you're willing to put the effort in to learn, few things will really be hidden from you in the long run. Motivation to be awesome is over half of actually being awesome. You'll get there, and I know that because I'm already seeing the evidence of it.
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 23, 2014, 10:18:09 AM
Quote from: ‽ on August 23, 2014, 12:56:07 AM
The real secret is putting in the effort to make some sense of what's going on. The only difference between you and me is that I've just been doing it longer.

If you're willing to put the effort in to learn, few things will really be hidden from you in the long run. Motivation to be awesome is over half of actually being awesome. You'll get there, and I know that because I'm already seeing the evidence of it.

Absolutely, I totally agree. I don't do this for profit or even to expect a forum to take off, it's entirely for the sport of it that I enjoy. That is why I always post working code, for others to benefit from, I just enjoy being educated in the workings of SMF and PHP, since there's no reason to do it otherwise, for me.

Everytime I get help with something, I read it and learn from it. I'm not always quick enough to get it right the next time, but slowly I'm seeing how to do things for myself, believe it or not, there's been three or four times as many things I've done for myself in-between help topics, but I couldn't have done that a year ago, and it's thanks to you guys and your amazing help. I really appreciate it! :D
Title: Re: Am I ignoring this user (on profiles page)
Post by: Arantor on August 23, 2014, 10:23:50 AM
Yup. I wrote most of my mods specifically to get to know SMF better, not because I needed them, and once you get a handle on how SMF works properly, the only barriers to doing what you want with it are the ones you place upon yourself.

For example, I'm currently building a gallery, which in itself is something I've never done but the principle is not significantly different to handling attachments (which I had to learn how SMF did, so I could do it in SimpleDesk), but I decided to be bold and set myself the rule of not making any file edits to SMF if *at all possible*. And so far, it's paying off. It's required some extreme creativity in getting around some of SMF's limitations but it's entirely possible with a bit of thought.

You're getting there, keep at it :)
Title: Re: Am I ignoring this user (on profiles page)
Post by: samborabora on August 24, 2014, 02:05:59 PM
Quote from: ‽ on August 23, 2014, 10:23:50 AM
Yup. I wrote most of my mods specifically to get to know SMF better, not because I needed them, and once you get a handle on how SMF works properly, the only barriers to doing what you want with it are the ones you place upon yourself.

For example, I'm currently building a gallery, which in itself is something I've never done but the principle is not significantly different to handling attachments (which I had to learn how SMF did, so I could do it in SimpleDesk), but I decided to be bold and set myself the rule of not making any file edits to SMF if *at all possible*. And so far, it's paying off. It's required some extreme creativity in getting around some of SMF's limitations but it's entirely possible with a bit of thought.

You're getting there, keep at it :)

Thanks for the boost, mate, really appreciate it. Will be keen to see your gallery when it's complete!