PDA

View Full Version : Whos Online Titles


Adrian Schneider
22 Apr 2006, 05:01
Prerequisite: [HowTo] Add Custom Pages to WOL (http://www.vbulletin.org/forum/showthread.php?t=82882)

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.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.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.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.

veenuisthebest
26 Nov 2008, 04:15
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