View Single Post
  #12  
Old 08-31-2002, 08:41 AM
tHE DSS's Avatar
tHE DSS tHE DSS is offline
 
Join Date: Jun 2002
Location: UK
Posts: 113
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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 :

PHP Code:
function getForumPermissions($usergroupID) {
    global 
$DB_site;
    
$forumCatPerm_result $DB_site->query("SELECT forumid FROM forumpermission WHERE canview=0 AND usergroupid=$usergroupID");
    if (!
$num_rows $DB_site->num_rows($forumCatPerm_result) <=0) {
        
$arrayIndex 0;
        while (
$row $DB_site->fetch_array($forumCatPerm_resultMYSQL_ASSOC)) {
            
$forumCatPerm_array[$arrayIndex++] = $row[forumid];
        }
    }

    if (isset(
$forumCatPerm_array)) {
        
$forumsCannotView_result $DB_site->query("SELECT forumid,parentlist FROM forum WHERE active=1");
        if (!
$num_rows $DB_site->num_rows($forumsCannotView_result) <=0) {
            
$arrayIndex 0;
            while (
$row $DB_site->fetch_array($forumsCannotView_resultMYSQL_ASSOC)) {
                
$forumParentList_temp explode(','$row[parentlist]);
                if (
$forumParentList_temp[1] != -1) {
                    if (
in_array($forumParentList_temp[1], $forumCatPerm_array)) {
                        
$forumsCannotView_array[$arrayIndex++] = $forumParentList_temp[0];
                    }
                }
            }
        }
        return 
$forumsCannotView_strList implode(","$forumCatPerm_array) . "," implode(","$forumsCannotView_array);
    } else {
        return 
$forumsCannotView_strList "";
    }

.... 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 :

PHP Code:
$forumsCannotView_strList getForumPermissions($bbuserinfo[usergroupid]);
$whereClause = ($forumsCannotView_strList != "") ? ("(forumid NOT IN ($forumsCannotView_strList)) AND") : ("");
$latest_discussions_num 12;
if (
$forumsCannotView_strList != "") {
    
$latestThreads_result $DB_site->query("SELECT threadid,title,lastpost,postusername,lastposter 
        FROM thread WHERE 
$whereClause visible=1 AND open=1 
            ORDER BY lastpost DESC 
                LIMIT 
$latest_discussions_num");
} else {
    
$latestThreads_result $DB_site->query("SELECT threadid,title,lastpost,postusername,lastposter 
        FROM thread WHERE visible=1 AND open=1 
            ORDER BY lastpost DESC 
                LIMIT 
$latest_discussions_num");
}
if (!
$num_rows $DB_site->num_rows($latestThreads_result) <=0) {
    while (
$row $DB_site->fetch_array($latestThreads_resultMYSQL_ASSOC)) {
        
$threadTitle "<a href=\"{forumsRoot}/showthread.php?s=$session[sessionhash]&threadid=$row[threadid]\" target=\"_blank\" class=\"smallLinks\">$row[title]</a>";
        
$threadStarter $row[postusername];
        
$lastPoster $row[lastposter];
        
$timezoneoffsetstamp $bbuserinfo[timezoneoffset] * 3600;
        
$timeDate date("$dateformat @ $timeformat"$row[lastpost] + $timezoneoffsetstamp);
        echo 
"$threadTitle | $threadStarter | $lastPoster | $timeDate";
    }

... 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.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01253 seconds
  • Memory Usage 1,822KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete