● Forum groups causing blocks to show more any once?

Wed Jul 18, 2018 10:11 pm
Clan Leader
Top Dog
Nuke Dev / Coder
3015 Posts
coRpSE
Currently Offline
Offline

Most Played:
This week: 77.7hrs.
Total Played: 195hrs.


  
There is life outside of the game.
Reputation: 7317.9
votes: 7
!!WARNING!!
Long post, don't skim, take time to read or don't read at all.


Here is what I am going to go over in this post, (in order),
  1. Explanation of whats happening and why.
  2. Send you to a video tutorial I did about forum permissions which I do talk about groups in it. (just  note, in the video I don't think i mentioned this, but if you set up groups like I said in there, this wouldn't be really an issue.).
  3. Little rant on how annoyed I am over this, mostly with those that lead me to believe they understood what i was talking about when they actually had no clue what I was talking about.
  4. Message to all that ask for my help.
  5. The code and what to edit
  6. How my code works, and explanation. Video just added.


Have you ran into a situation where you went to add a block onto your site, but you only wanted specific groups to see it, to you went in and set the block to groups only, and you selected a few groups, and after doing that, you find that there is multiple blocks now showing on your home page?

Well, if this has happened to you, and you came to me before and asked about it, then I probably told you to edit your groups to make it easier. I still stand by that. I don't get why a clan would set up something like, Leader, lieutenant, and members, and not put the leaders and lieutenant into the member group. Just say everyone in the clan was in the member group, then just say they got promoted to lieutenant, leave them in the member group, just add them to the lieutenant group. That way is you want something to be shown only to members, all you have to do is set the item to the members and that's it.

I do go over this in my forum permissions video tutorial.
Please login to see this link
Get registered or Log in


Well, I coded a workaround because some people that ask for my help choose to ignore it, or just didn't understand me, and when it effects them, they don't understand why even though they were told about it. I am not mentioning names, but, in the last week, this has popped up 4 times. Yes, that is right, four times. What I find strange is I haven't had anyone ask me about this issue for maybe a year, then I get it four times in 1 week.

Here is essentially what your would see if you run into this problem:
Expand

But from your admin panel it just was there once.
Expand

Well, it comes to light only when trying to set a block only for specific groups to see. Otherwise this goes unseen. If you set up the groups with careful planning knowing that this could happen, its easy to avoid, but, if you had no knowledge of this happening, it is easy to cause this issue with setting of the groups.
Expand

Well, finally I got around to coding a quick fix for this and I will explain my fix and how it works below. You can see the actual diffchecker here:
Check it out here:
Please login to see this link
Get registered or Log in


Here is the code to fix this issue:

Open up your public_html/mainfile.php

Find:

PHP:  [ Select all ]

        if (empty($blockrow[$i]['bkey'])) {
 
           if ( ($view == '0' || $view == '1') ||
 
              ( ($view == '3' AND is_user()) ) ||
 
              $view == '4' AND is_admin()) ||
 
              ( ($view == '2' AND !is_user())) ) {
 
               render_blocks($side$blockrow[$i]);
 
           } else {
 
               if (substr($viewstrlen($view)-1) == '-') {
 
                   $ingroups explode('-'$view);
 
                   if (is_array($ingroups)) {
 
                       foreach ($ingroups as $group) {
 
                           if (isset($userinfo['groups'][($group)])) {
 
                               render_blocks($side$blockrow[$i]);
 
                           }
 
                       }
 
                   }
 
               }
 
           }
 
       }
 
   }
 
   return;

 
Replace with:

PHP:  [ Select all ]

if (empty($blockrow[$i]['bkey'])) {
 
           if ( ($view == '0' || $view == '1') ||
 
              ( ($view == '3' AND is_user()) ) ||
 
              $view == '4' AND is_admin()) ||
 
              ( ($view == '2' AND !is_user())) ) {
 
               render_blocks($side$blockrow[$i]);
 
           } else {
 
               if (substr($viewstrlen($view)-1) == '-') {
 
                   $ingroups explode('-'$view);
 
                   if (is_array($ingroups)) {
                        
$cnt 0;
 
                       foreach ($ingroups as $group) {
 
                           if (isset($userinfo['groups'][($group)])) {
 
                               $cnt++;
                     
         }
                         
 }
                    if (
$cnt != 0){
                    
render_blocks($side$blockrow[$i]);
 
                       }
 
                   }
 
               }
 
           }
 
       }
 
   }
 
   return;

 
Save & Close


Now, you may see that I am having you replace more than the code that is necessary, and that's because I wanted to have you replace a whole section because it less likely that you may mess something up, especially with the count of the closing }'s.

Now, how does this work? Well, its simple. before hand, the code would check to see how many groups were called, and depending on how many time your appeared, would show the block once per group, so if you were in 4 groups, you would see it 4 times. Now, my code still uses the loop they had, but instead, does some simple math..

My code:

PHP:  [ Select all ]

                    if (is_array($ingroups)) {
                        
$cnt 0;
 
                       foreach ($ingroups as $group) {
 
                           if (isset($userinfo['groups'][($group)])) {
 
                               $cnt++;
                     
         }
                         
 }
                    if (
$cnt != 0){
                    
render_blocks($side$blockrow[$i]);
 
                       }
 
                   

 
First thing you will see is $cnt = 0;. What I am doing there is setting a variable that I created to be 0. So, at that point, if I wanted to display that variable using a echo or something, it would just show the number 0. Now, the next line down is the foreach, that is the loop that is taking the array of all the groups and looping thought each one.

The next line down is checking to see if you belong to the group that this block should be shown to. If you do, then the, next line down adds a 1 to the variable I created before that was equal to 0. So, each time the $cnt++; is run though the loop, lets say 3 times, then it added a "1" three times, (0+1+1+1=3).

So, the last part of my code is this:
if ($cnt != 0)
which is saying, it the variable $cnt does NOT equal to 0, then show the block once. So it doesn't matter how may groups you belong in, as long as your count is over 0 to be able to see it, then you will, otherwise, you wont see it.

Simple fix. I know there are other ways that this could have been accomplished, and short of a rewrite of sorts, this was the easiest way. So if your looking at putting this in, then the instructions are above, and exactly how the code works has also been explained.

Here is a video I finally got made:


Learn more about Comparison Operators:
Please login to see this link
Get registered or Log in


Learn more about Incrementing / Decrementing Operators:
Please login to see this link
Get registered or Log in
Thu Jul 26, 2018 1:00 am
NOOB!!!
4 Posts
Reputation: 59.8
Yeah, sorry bud about fucking up. You know I am not grat at listening and following instructions. Heck, I'm lucky that my wife has not left me yet. Thanks again for fixing our site again and I will try following instructions a bit better
Thu Jul 26, 2018 1:11 am
Original Poster
Clan Leader
Top Dog
Nuke Dev / Coder
3015 Posts
coRpSE
Currently Offline
Offline

Most Played:
This week: 77.7hrs.
Total Played: 195hrs.


  
There is life outside of the game.
Reputation: 7317.9
votes: 7
It's no problem, The day I wrote this "originally", I was having a bad day, but I also couldn't believe that I had 3 clans that had the same issue, and you and one other I talked to directly and helped on TS. Granted the other one did also just have some internal issues with their clan and there "web" guy.

But like I said to you, if you still don't understand what I am talking about, even after I explain, ask questions. It's the only way you or anyone reading this thread is going to learn. I know for a fact that I am going to run into these issues again, since this is not the first time. I actually banned a member of our clan from doing any work on his PC. He couldn't even install a mod or a game without me being connected. I just got tired of fixing his PC. lol...


 
Thu Jul 26, 2018 1:18 am
NOOB!!!
4 Posts
Reputation: 59.8
Yeah, my bad.

Well, thanks again for what you did for us and keep up what your doing for this community. We need more of you to keep doing this. you know I would help if I knew what I was doing.


 
Thu Jul 26, 2018 12:05 pm
Original Poster
Clan Leader
Top Dog
Nuke Dev / Coder
3015 Posts
coRpSE
Currently Offline
Offline

Most Played:
This week: 77.7hrs.
Total Played: 195hrs.


  
There is life outside of the game.
Reputation: 7317.9
votes: 7
n/p


 
Forums ©