View Single Post
  #13  
Old 10-24-2000, 04:20 PM
Guest
 
Posts: n/a
Default

Ok I hacked the hack so that if a thread is "invisible" it will not be shown in the users favorites.

Also it nows checks if a user has access to a thread before showing it in their favorites.

The idea is that a user may have added a thread and now has lost access to it for reasons shown in my previous post. The thread isn't actually removed from his/her list but is just not shown to them. This will allow it to "re-appear" to them if they are again given access to it. The thread table is very small as it only contains 3 id fields, the thread id, the id of the folder it goes in (if it has one) and the id of the field itself.

Below is my access checking code. My main goal has been as little database access as possible and I believe John needs to do this sort of thing in other places to help the optimization. I could have queried the database for every thread to decide to post it or not but that is bad design and something vB is very guilty of doing. My way of doing it is to build parts of your query using logic and then put your constructed query to work in the main query:

Code:
   // These usergroups really need to be re-done, this is a nightmare!
   // This gets the forums that our usergroup has SPECIFIC canview access to (0 or 1)
   $q_perms = $DB_site->query("SELECT forumid,canview FROM forumpermission
                               WHERE usergroupid = $bbusergroupid");
   // This gets our generic canview access
   // If we do not have a specific access defined in the first query than we use the second query
   // for our access to that forum.
   $q_uperms = $DB_site->query_first("SELECT canview FROM usergroup WHERE usergroupid = $bbusergroupid");
   $canview = $q_uperms[canview];  
   // $canview = 0 / We can't view any forums unless we have specific access to above
   // $canview = 1 / We can view all forums unless we have specific access not to above
   if ($canview == 1) // We view all forums by default, hide those we have explicit non access to
   {
      while ($query = $DB_site->fetch_array($q_perms))
      {
         $onethread = 0;
         if ($query[canview] == 0)
         {
            if ($onethread == 0)  
            {
               $forums .= " AND (forumid <> $query[forumid] ";
               $onethread = 1;
            }
            else
            {
               $forums .= " OR forumid <> $query[forumid] ";
            }
         }
      }
      if ($onethread == 1)
      {
         $forums .= ")";  
      }      
   }
   else // We can view no forums by default, show those we have explicit read access to
   {
      while ($query = $DB_site->fetch_array($q_perms))
      {
         $onethread = 0;
         if ($query[canview] == 1)
         {
            if ($onethread == 0)  
            {
               $forums .= " AND (forumid = $query[forumid] ";
               $onethread = 1;
            }
            else
            {
               $forums .= " OR forumid = $query[forumid] ";
            }
         }
      }
      if ($onethread == 1)
      {
         $forums .= ")";  
      }      
   }

   $q_thread = $DB_site->query("SELECT thread.iconid, icon.title AS icontitle, icon.iconpath, open, thread.title AS threadtitle,
                         lastpost, postusername,lastposter, views, replycount, fav_threads.userid, fav_threads.threadid,
                         fav_threads.folderid, folder                      
                         FROM fav_threads,thread
                         LEFT JOIN fav_folders ON (fav_threads.folderid = fav_folders.folderid)
                         LEFT JOIN icon ON (icon.iconid = thread.iconid)
                         WHERE fav_threads.userid = $bbuserid
                               AND thread.threadid = fav_threads.threadid
                               AND thread.visible = 1
                               $forums
                         ORDER by folder,thread.title");
I then take "$forums" and place it into my main query that retrieves the threads. Remember I only have one query that gets everything for showing the threads (it gets the icons, the posters, everything that is shown normally when you look at a list of threads in a normal forum). Can we say forumdisplay is need of a query optimization (I think so).

Let me put in page breaks for long pages and I will be done (which isn't easy as I like to make sure to return you to the page you were on from any function you may access)

[Edited by rangersfan on 10-24-2000 at 01:12 PM]
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01199 seconds
  • Memory Usage 1,784KB
  • 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
  • (1)bbcode_code
  • (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_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
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete