Wrote some PHP code today to make the Who Is Online (WOL) in the forums work properly with the new home page:
Wrote this global plugin to add the location to both the user table (for members) and session table (for guests + registered users)
<?php
if (THIS_SCRIPT != 'misc' and THIS_SCRIPT != 'ajax') {
$mylocation = THIS_SCRIPT;
if (strlen($mylocation) < 2) {
$mylocation = "unknown";
}
if ($vbulletin->userinfo['userid'] > '0') {
$query = "UPDATE " . TABLE_PREFIX . "user SET parentemail = '" . $mylocation . "' WHERE userid = " . $vbulletin->userinfo['userid'];
if (false) {
error_log("UID: " . $vbulletin->userinfo['userid'] . ' loc_cookie ' . $mylocation . " query: " . $query . "\n", 3, '/var/log/apache2/debug/cookiesetdbupdate.log');
}
$db->query_write($query);
}
// borrowed unused incalendar DB column in the session table until I have a change to create a new one
if (isset($vbulletin->session->vars['sessionhash']) and strlen($vbulletin->session->vars['sessionhash']) > 10) {
$query = "UPDATE " . TABLE_PREFIX . " session SET incalendar = '" . $mylocation . "' WHERE sessionhash = '" . $vbulletin->session->vars['sessionhash'] . "'";
if (false) {
error_log("UID: " . $vbulletin->userinfo['userid'] . ' loc_cookie ' . $mylocation . " query: " . $query . "\n", 3, '/var/log/apache2/debug/cookiesetdbupdate.log');
}
$db->query_write($query);
}
}
In addition, wrote some quick PHP code for the online.php
in functions_online.php
:
<?php
case 'index':
if($userinfo[userid] > '0')
{
$query = "SELECT lastlocation,lastactivity FROM " . TABLE_PREFIX . "user WHERE userid = ".$userinfo[userid]." ORDER BY lastactivity DESC LIMIT 1";
$userloc = $vbulletin->db->query_first("SELECT lastlocation,lastactivity FROM " . TABLE_PREFIX . "user WHERE userid = ".$userinfo['userid']." ORDER BY lastactivity DESC LIMIT 1");
error_log("UID: " . $vbulletin->userinfo['userid'] . ' loc ' . $userloc['lastlocation'] . ' Query: '.$query. "\n", 3, '/var/log/apache2/debug/online_neo.log');
}
else
{
if(strlen($vbulletin->session->vars['incalendar']) > 10)
$guestloc = $vbulletin->session->vars['incalendar'];
}
if($userloc['lastlocation'] == 'home' OR $guestloc == 'home')
{
$userinfo['action'] = 'Viewing Home Page - Featured Discussion';
$userinfo['where'] = '<a href="' . $vbulletin->options['forumhome'] . '.php' . $vbulletin->session->vars['sessionurl_q'] . '">' . $vbulletin->options['bbtitle'] . '</a>';
}
else
{
$userinfo['action'] = 'Viewing Forum Home and Stats Page';
$userinfo['where'] = '<a href="https://www.unix.com/forum.php' . $vbulletin->session->vars['sessionurl_q'] . '">Forums: ' .$vbulletin->options['bbtitle'] . '</a>';
}
break;