View Full Version : Function to retrieve the forums a user can access
This is something I once wrote for someone (think it was merk?), and kept it in a file, and finally got around to clean it up and wrap it in a function.
Very useful for some hacks, hope this helps at least some of you.
Here is the full function, along with some basic instructions:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Great function, very usefull indeed. Thanks.
Dark_Wizard
08 Aug 2002, 10:42
Wow...very useful I agree. Thank you!
I should mention that the function only issues 3 queries, one of which VERY fast. :)
I seem to be having some problems with this.
I've added the entire function to functions.php. I added it as the second-to-last function, above doshutdown.
I tried to use the function from global.php (the forums, not the admin). Right above the part of global.php that parses the css (headinclude), header, and footer.
I've tried $jjr512=get_allowed_forums();. I've tried $jjr512=get_allowed_forums('canview',-1,',');. I've tried a lot of things. But whenever I try to use the function, I get this error: "Warning: Bad arguments to implode() in /home/jjr512/public_html/testvb/admin/functions.php on line 2289" Now as I have it in my functions.php, Line 2289 is:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
What am I doing wrong?
MrLister
11 Aug 2002, 17:36
great, thank you!
tHE DSS
16 Aug 2002, 23:36
This is a great function, and i'm using it right now for some custom statistics.
Thing is though, Guests and normal members and stuff get permissions returned that they don't have "canview" permissions to.
Any thoughts?
tHE DSS
17 Aug 2002, 16:24
I think what is happening, is if a forum is using permissions from it's parent forum, then it doesn't get taken into account.
If you know what I mean?
very usefull, as lesane said before. thanks for posting it.
tHE DSS
31 Aug 2002, 10:41
As I posted before in this thread - the above function does not return results of forums a user cannot "view", if the forum is using default permissions from it's parent forum.
Our board uses only forum default permissions, inherited from it's parent forum - we rely on usergroup permissions, and this does us absolutely fine.
The other night, I really really needed to make sure I could restrict some queries from returning data that comes from forums any certain usergroup cannot view, so I made the following function - it's a little sloppy in places, but it's not that bad - the main thing is, it works :
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
.... it's tested, and works.... it checks the 'forumpermission' table, and takes the forumid of parent forums (category forums) that have usergroup permissions set, and then queries the forum table, making a list of forums in that category, that the usergroup cannot view.
As an example, we can take the last 12 posts made, from forums that only the viewers usergroup has 'canview' access to :
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
... basically, if the function returns an empty string, there are not restrictions, and the 2nd query is actioned, which returns all forums... obviously, if there are restrictions, then the restricted forums get filtered out of the query.
I find this very handy for some of our non-vB pages.... and I post it simply in-case sombody likes the concept.
tHE DSS
31 Aug 2002, 10:53
... actually, I think the 2nd query in the example can be left out, cleaning up the example code a little.... basically, the 'else {}' bit in the example (containing the alternate query) can be left out.
How could I sue this to get the Top thread by replies and the Top Thread by views and only have the right thread show up according to what the user is able to view?
Originally posted by tHE DSS
... actually, I think the 2nd query in the example can be left out, cleaning up the example code a little.... basically, the 'else {}' bit in the example (containing the alternate query) can be left out.
tHE DSS
31 Aug 2002, 14:10
You could use this :
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
... which will get the stuff you need, for threads that are inside the visitors viewable forums, and that are open... no locked threads will be returned.
As far as i've tested, this only works (and only intended) for forums that have parent forum permissions - it doesn't cater for access masks... I believe that forums using their parent forum permissions show up in BLUE, in the forum permissions panel in the Admin CP... like this :
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
... i've done abit more testing since, and believe that forums using custom permissions may also be able to benefit from this function... they show up in red in the AdminCP.
Best to test it out yourself though, to be sure in your own mind.
You can simply echo out the returned string list, like this :
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
... then check all the comma separated values, against your forum ids.
Play about with forum permissions, and log-in and out as different member groups, and see if the forums that get returned are the only ones viewable by that group.
I don't mean to sound stupid here, but you are way over my head on this one. :)
The two queries I need to check permissions for are:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
What code do I need to add to for these? I inserted the whole function that Firefly posted in the admin/functions.php file already, so it is there.
I really appreciate your help on this. I am totally lost when it comes to the permissions checking. :)
tHE DSS
31 Aug 2002, 14:54
After calling my function, you can use these two queries :
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
... those are included in the example I previously gave for your needs... but I chose to only query specific fields.... the two here, i've put the '*' when SELECTing, so that you get all fields returned.
... and i've also taken out the :
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
.... bit, because, as I said previously, it's abit sloppy in places... the WHERE clause that is generated with this :
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
.. after calling my function, sorts it out.
Ok, I think I understand what you are doing here. Where do put the function? In functions.php? And how do I call it in the index.php for the 2 queries?
tHE DSS
31 Aug 2002, 16:42
I'm going out in a few hours to get p***ed as a fart, but tomorrow, i'll start a new thread for this function, i'll clean up the code and give easy instruction.
But to answer your question here, yeah, you can place it in 'functions.php' if you wish, and you call it like this :
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
You only need to call it the once inside a script, and then you have all the forums IDs the current viewer is allowed to view as a string list, in $forumsCannotView_strList, which you can use however you want.
Thanks for taking the time and patience with me on this. I really appreciate it. I'll be looking forward to the new thread and your instructions tomorrow then. Have one for me tonight (today, actually for me). I'm home watching the little one. :)
Originally posted by tHE DSS
I'm going out in a few hours to get p***ed as a fart, but tomorrow, i'll start a new thread for this function, i'll clean up the code and give easy instruction.
But to answer your question here, yeah, you can place it in 'functions.php' if you wish, and you call it like this :
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
You only need to call it the once inside a script, and then you have all the forums IDs the current viewer is allowed to view as a string list, in $forumsCannotView_strList, which you can use however you want.
So how could I use this to build a drop down box with a list of forums that the current user has permission to see? Would need the forum name as well as forum id. Here's the part that would have to be built:
Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------
Thanks!
tHE DSS
20 Oct 2002, 12:53
dwh, i've had a go at your request in this thread.
http://www.vbulletin.org/forum/showthread.php?s=&postid=311732#post311732
vBulletin® v3.6.12, Copyright ©2000-2012, Jelsoft Enterprises Ltd.