Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-28-2007, 10:11 PM
SDB SDB is offline
 
Join Date: Feb 2004
Posts: 136
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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
Reply With Quote
  #2  
Old 01-29-2007, 03:21 AM
harmor19 harmor19 is offline
 
Join Date: Apr 2005
Posts: 1,324
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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++; 
         
        } 
    } 
Reply With Quote
  #3  
Old 01-29-2007, 03:31 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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)
Reply With Quote
  #4  
Old 01-29-2007, 06:59 AM
SDB SDB is offline
 
Join Date: Feb 2004
Posts: 136
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:30 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.08488 seconds
  • Memory Usage 2,201KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete