Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin Tips & Tricks
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Whos Online Titles
Adrian Schneider's Avatar
Adrian Schneider
Join Date: Jul 2004
Posts: 2,528

 

Show Printable Version Email this Page Subscription
Adrian Schneider Adrian Schneider is offline 04-21-2006, 10:00 PM

Prerequisite: [HowTo] Add Custom Pages to WOL

If you have spent any time adding your custom scripts to show up as valid locations, you have probably wondered how to get the title of the blog entry, download, help ticket, store item, etc...

For my example, I'll base it on my project I was working on which was a blog system. Assuming the user views viewblog.php?userid=1, we can access the userid value of 1 using the 'values' element of $userinfo. The values element contains all the $_GET info of the user that was viewing.
PHP Code:
else if ($filename == 'viewblog.php')
{
    
$userinfo['activity'] = 'blog_view';
    if (
$userinfo['values']['userid'])
    {
        global 
$blogUserids;
        
$blogUserids .= ',' $userinfo['values']['userid'];
        
$userinfo['activity'] = 'blog_view';
    }

This adds to the list of userids that need the title queried for.


The next step is to retrieve those titles that we need, and to do this we use the "online_ids_titles" hook.
PHP Code:
global $blogUserids$wol_blogUserids;
if (
$blogUserids)
{
    
$blogUseridQuery $vbulletin->db->query_read("
        SELECT userid, title
        FROM " 
TABLE_PREFIX "blog_settings
        WHERE userid IN (0
$blogUserids)
    "
);
    
$wol_blogUserids = array();
    while (
$blogUser $vbulletin->db->fetch_array($blogUseridQuery))
    {
        
$wol_blogUserids[$blogUser['userid']] = $blogUser['title'];
    }

It is crucial that you give $blogUserids and $wol_blogUserids global scope here, because we are currently inside a function! The above code only functions if $blogUserids is true (contains value) so it will not function if no users are currently viewing any blogs. Each row from the database will be stored in an array associating the ID with the Title so we can easily access it later.

The final step is to show the data... in my plugin in the "online_location_unknown" hook, I have a switch for $userinfo['activity'] (which is defined above), so I can assign the text and newly retrieved title of the blog.
PHP Code:
switch ($userinfo['activity'])
{
// ...
    
case 'blog_view':
        global 
$wol_blogUserids;

        
$blogUserid =& $userinfo['values']['userid'];
        
$blogTitle =& $wol_blogUserids[$blogUserid];
        
$userinfo['action'] = 'Viewing Blog';
        
$userinfo['where'] = '<a href="viewblog.php?' $vbulletin->session->vars['sessionurl'] . "userid=$blogUserid\">$blogTitle</a>";
        
$handled true;
        break;

// ...

Again, we need to give global scope (this time to $wol_blogUserids), so that we can access the title of the blog. I assign $blogUserid and $blogTitle the values we want to use in the link, just because it makes writing the string easier and takes up less horizontal space. $userinfo['action'] is the main action that displays, and $userinfo['where'] is the extra optional bit of information that is displayed to the side or below.

To make any use of this, you will have to heavily modify it to work with your table structure and vb extension, but this should give you enough of an idea how to do it to be at least somewhat successfull.
Reply With Quote
  #2  
Old 11-26-2008, 02:15 AM
veenuisthebest's Avatar
veenuisthebest veenuisthebest is offline
 
Join Date: Mar 2008
Location: India
Posts: 1,416
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Worked great! Thank you so much for this. I don't know how many times and on how many forums I have asked this. Thanks again

alright, just one question plz. How do I get a third variable available for userinfo[where]. Say we have id and title, I also want to extract url column value from database to use in the location path.

I am able to do it by querying url ofcourse and creating another global variable $wol_urls.

Just wanted to know if its the best way. Thanks
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 01:45 AM.


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.11701 seconds
  • Memory Usage 2,211KB
  • Queries Executed 15 (?)
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
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (2)post_thanks_box
  • (2)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit_info
  • (1)postbit
  • (2)postbit_onlinestatus
  • (2)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_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