Thread: Forum Display Enhancements - Remove Spiders from Who's Online
View Single Post
  #9  
Old 07-15-2007, 04:47 PM
mfyvie mfyvie is offline
 
Join Date: Mar 2007
Location: Zurich, Switzerland
Posts: 336
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Some of you might be wondering what is so different about this mod, so I'll take a little bit of time to explain how you might use it to do some different stuff.

This mod actually classifies each session as spider or normal user when the session is created and stores the result in the session table. Why? Because it makes it very easy for us to check the "spider status" on any session from any page, WITHOUT having to compare the user agent against a list of known user agents every time.

Why is this better? Two reasons, the first is speed and the second is flexibility. By default the mod will suppress the spiders from the statistics (it won't block anything). But we could use this mod to do more if we wanted.

If you look in the session table you'll see an extra column called "spider", the values are -1 (normal user), 0 (not yet determined - you'll rarely see this) and 1 (spider). Now you can easily change things depending on whether a spider is viewing the page or not. You could put something in a template like this:

Code:
<if condition="$session[spider] == 1">Come into my parlour, said the spider to the fly</if>
Now that text would appear only to spiders. Along the same lines you could show text only to real users like this:

Code:
<if condition="$session[spider] == -1">Don't tell the spiders, but they can't see this text.</if>
You could also use it inside any plugin simply by testing the value of $vbulletin->session->vars['spider'] like this:

Code:
if ($vbulletin->session->vars['spider'] == 1)
{
    //Some stuff to do when we have a spider visiting
}
Putting a variable into the session table to use elsewhere is the same kind of approach used in GLA (some of you might have seen this recently).

So with a little bit of imagination some of you might also be able to see that this mod could help you do all sorts of new things (I've seen many requests for example from people who want to display different links or pages to spiders than normal users - this would be simple using the above techniques).

What if you wanted to get some quick statistics to show how many users or guests are online. Easy - now you can use a simple SQL query like this:

Code:
SELECT COUNT(*) FROM session WHERE userid = 0 AND spider =-1
This would show the number of non-spider guests in the connection table (but you'd have to remember to add something onto the end to limit the last activity to the last 15 minutes (or whatever you have it configured to), so the final code in a plugin might look something like this:
Code:
$guests = implode("", $vbulletin->db->query_first("SELECT COUNT(*) FROM session WHERE userid = 0 AND spider =-1 AND lastactivity > " . (TIMENOW - $vbulletin->options['cookietimeout']) . "))
Again you could vary it to something like userid > 0 for members, or spider = 1 for the spiders. This way you can get the totals quickly from any page with just a single line of code and a single query.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01193 seconds
  • Memory Usage 1,778KB
  • 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
  • (5)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_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