vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   help.. permission check for "last 5 posts.." (https://vborg.vbsupport.ru/showthread.php?t=137801)

SDB 01-28-2007 10:11 PM

help.. permission check for "last 5 posts.."
 
Hi

Could someone urgently amend this query for me to exclude posts the viewing user does not have permission to view?

$threads = $vbulletin->db->query_read("SELECT threadid, title, lastpost, lastposter
FROM " . TABLE_PREFIX . "thread
WHERE visible = '1' AND open = '1'
ORDER BY lastpost DESC LIMIT 5
");

Thanks

Simon

harmor19 01-29-2007 03:21 AM

This gets the last 5 threads. I would've edit it to show the last 5 posts but I'll let you do that.

PHP Code:

$count 0;
$getposts $db->query_read(
    SELECT DISTINCT thread.title AS title, thread.threadid AS threadid, forum.forumid AS forumid
    FROM " 
TABLE_PREFIX "post AS post 
    LEFT JOIN " 
TABLE_PREFIX "thread AS thread 
    ON post.threadid = thread.threadid
    LEFT JOIN " 
TABLE_PREFIX "forum AS forum
    ON thread.forumid = forum.forumid
    ORDER BY postid DESC"
);     
    while(
$post $db->fetch_array($getposts)) 
    { 
          
        
$forumperms fetch_permissions($post['forumid']); 
        if ((
$forumperms $vbulletin->bf_ugp_forumpermissions['canview']) OR ($forumperms $vbulletin->bf_ugp_forumpermissions['canviewthreads'])) 
        { 
            if(
$count <= 5
            { 
                
$latestthreads2 .= "<b>Title</b>: <a href='showthread.php?t=$post[threadid]'>".$post['title']."</a><br />"
         
            } 
             
        
$count++; 
         
        } 
    } 


Adrian Schneider 01-29-2007 03:31 AM

2 tips:

-Do the forum permission checking prior to the query (generating a comma-delimited list of forumids they can or can't see): WHERE forumid NOT IN ($ids)

-Only show posts from the past few days, which would utilize the date index (greatly reducing the amount of juice it will take to bring up the records)

SDB 01-29-2007 06:59 AM

Thanks guys :)

I've changed it to the following (which I've taken from somewhere, can't remember where now!) ..

Code:

$blockforums = "";
foreach($vbulletin->forumcache AS $forum) {
    $forumid = $forum['forumid'];
    $forumperms =& $vbulletin->userinfo['forumpermissions']["$forumid"];

    if (!isset($vbulletin->forumcache["$forumid"]) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) OR !verify_forum_password($forumid, $vbulletin->forumcache["$forumid"]['password'], false))
    {
        $blockforums .= ','.$forum['forumid'];
    }
}


$threads = $vbulletin->db->query_read("SELECT threadid, title, lastpost, lastposter
                                                                        FROM " . TABLE_PREFIX . "thread
                                                                        WHERE visible = '1' AND open = '1'
                                                                    AND forumid NOT IN (0$blockforums)
                                                                        ORDER BY lastpost DESC LIMIT 5
                                                                        ");

Does that look ok?

Thanks again

Simon


All times are GMT. The time now is 04:04 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00943 seconds
  • Memory Usage 1,730KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete