Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Who's Online

2456

Comments

  • Hi,

    I still can't see any guest count!

    Only members name when they're signed in, so who to turn it so it show's guest as well as members?

    Thanks
  • This addon is not workin for me. Back on March 6 there was a post about modifying 2 files, but now I don't see anything about what those files are.

    I have vanilla 1.1.1, and whosonline 1.2?

    I appreciate the help.
  • OK the upgrade to 1.2 fixed it all.. I thought I had done that.. but posting here I noticed not.... Whois is very important for my application...thanks for the work.
  • anybody else getting the bug that everything is displayed as being active "1 hour ago" in the title?
  • This seems to have fixed itself, which leads me to believe it was spambots. Who knows!
  • Hi, I'm still having a problem to get the user's names listed inline, rather than each per line and Mr Do hack above didn't seem to work!

    Any thoughts?
    Thanks.
  • how doesnt it work? it works for me..

    I think the problem is that I forgot to give you the line to add the style file? just put that css style into a css file allready active, at the bottom of vanilla.css in the styles folder for example..
  • Ok... here is the default.php:

    <?php
    /*
    Extension Name: Who's Online
    Extension Url: http://www.thirty5.net/code/vanilla/whosonline/
    Description: Adds a "who's online" list to the panel.
    Version: 1.2
    Author: David Knowles, Julien Cassignol, Michael Schieben
    Author Url: mailto:dknowles2@gmail.com

    Additional Author: Michael Schieben - michael@twoantennas.com (Adaption to Vanilla 1.0)

    */
    $Context->Dictionary["MenuOptions"] = "Menu Options";
    $Context->Dictionary["HideWhosOnline"] = "Hide the \"Who's Online\" panel";
    $Context->Dictionary["Phantom"] = "Hide my username from the \"Who's Online\" panel";


    class WhosOnline {
    var $Name;
    var $Context;

    function WhosOnline(&$Context) {
    $this->Name = "WhosOnline";
    $this->Context = &$Context;
    }

    function GetWhosOnline() {
    $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder");
    $s->SetMainTable("User", "u");
    $s->AddSelect(array("Name", "UserID", "DateLastActive", "Preferences"), "u");
    $s->AddWhere("u", "DateLastActive", "", "DATE_SUB(NOW(), INTERVAL 5 MINUTE)", ">=", NULL, NULL, 0);
    $result = $this->Context->Database->Select($s, $this->Name, "GetRecentUsers", "An error occurred while attempting to retrieve the requested information.");
    if ($this->Context->Database->RowCount($result) == 0) {
    return NULL;
    } else {
    $my_array = array();
    while ($rows = $this->Context->Database->GetRow($result)) {
    if ($rows["Preferences"]) {
    $settings = unserialize($rows["Preferences"]);
    if (array_key_exists("Phantom", $settings))
    $phantom = ForceBool($settings["Phantom"], 0);
    else
    $phantom = false;
    } else {
    $phantom = false;
    }
    array_push($my_array, array("Name" => $rows["Name"], "UserID" => $rows["UserID"],
    "DateLastActive" => $rows["DateLastActive"], "Phantom" => $phantom));
    }
    return $my_array;
    }
    }

    function GetGuestCount() {
    $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder");
    $s->SetMainTable("IpHistory", "i");
    $s->AddSelect("IpHistoryID", "i", "GuestCount", "COUNT");
    $s->AddWhere("i", "UserID", "", 0, "=");
    $s->AddWhere("i", "DateLogged", "", "DATE_SUB(NOW(), INTERVAL 1 MINUTE)", ">=", 'and', NULL, 0);
    $result = $this->Context->Database->Select($s, $this->Name, "GetGuestCount", "An error occurred while attempting to retrieve the requested information.");
    $row = $this->Context->Database->GetRow($result);
    return $row["GuestCount"];
    }

    function GetNextIpLetter($my_ip) {
    $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder");
    $s->SetMainTable("IpHistory", "i");
    $s->AddSelect("RemoteIp", "i");
    $s->AddWhere("i", "UserID", "", 0, "=");
    $s->AddWhere("i", "RemoteIp", "", "$my_ip([a-z])*$", "regexp");
    $s->AddWhere("i", "DateLogged", "", "DATE_SUB(NOW(), INTERVAL 30 MINUTE)", ">=", 'and', NULL, 0);
    $s->AddOrderBy("RemoteIp", "i", "desc");
    $s->AddLimit(0, 1);
    $result = $this->Context->Database->Select($s, $this->Name, "UpdateGuestLastActive", "An error occurred while logging user data.");

    if ($this->Context->Database->RowCount($result) > 0) {
    $row = $this->Context->Database->GetRow($result);
    if (preg_match("/([a-z])+$/", $row["RemoteIp"], $ip_letter))
    return ++$ip_letter[0];
    else
    return "a";
    } else {
    return "";
    }
    }

    function GetIpHistoryID($my_ip) {
    $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder");
    $s->SetMainTable("IpHistory", "i");
    $s->AddSelect("IpHistoryID", "i");
    $s->AddWhere("i", "UserID", "", 0, "=");
    $s->AddWhere("i", "RemoteIp", "", $my_ip, "=");
    $s->AddOrderBy("IpHistoryID", "i", "desc");
    $s->AddLimit(0, 1);
    $result = $this->Context->Database->Select($s, $this->Name, "GetIpHistoryID",
    "An error occurred while attempting to retrieve the requested information.");
    $row = $this->Context->Database->GetRow($result);
    return $row["IpHistoryID"];
    }

    function UpdateDateLastActive() {
    $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder");

    if (isset($_COOKIE['IpHistoryID'])) {
    $s->SetMainTable("IpHistory", "i");
    $s->AddWhere("i", "IpHistoryID", "", $_COOKIE['IpHistoryID'], "=");
    $this->Context->Database->Delete($s, $this->Name, "UpdateDateLastActive", "An error occurred while deleting guest profile");
    setcookie('IpHistoryID', '', time() - 3600);
    }
    $s->Clear();
    $s->SetMainTable("User", "u");
    $s->AddFieldNameValue("DateLastActive", "now()", 0);
    $s->AddWhere("u", "UserID", "", $this->Context->Session->UserID, "=");
    $result = $this->Context->Database->Update($s, $this->Name, "UpdateDateLastActive", "An error occurred while updating your account.");
    }

    function UpdateGuestLastActive() {
    $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder");
    if (isset($_COOKIE['IpHistoryID'])) {
    $s->Clear();
    $s->SetMainTable("IpHistory", "i");
    $s->AddFieldNameValue("DateLogged", "now()", 0);
    $s->AddWhere("i", "IpHistoryID", "", $_COOKIE['IpHistoryID'], "=");
    $result = $this->Context->Database->Update($s, $this->Name, "UpdateGuestLastActive", "An error occurred while logging user data.");
    } else {
    $my_ip = GetRemoteIp(1);
    $ip_letter = $this->GetNextIpLetter($my_ip);
    $s->Clear();
    $s->SetMainTable("IpHistory", "i");
    $s->AddFieldNameValue("UserID", 0);
    $s->AddFieldNameValue("RemoteIp", $my_ip . $ip_letter);
    $s->AddFieldNameValue("DateLogged", "Now()", 0);
    $this->Context->Database->Insert($s, $this->Name, "UpdateGuestLastActive", "An error occurred while logging user data.");
    setcookie('IpHistoryID', $this->GetIpHistoryID($my_ip . $ip_letter));
    }
    }

    }

    $WhosOnline = $Context->ObjectFactory->NewContextObject($Context, "WhosOnline");

    if (!in_array($Context->SelfUrl, array("signin.php", "leave.php", "post.php", "passwordrequest.php", "passwordreset.php"))) {
    if ($Context->Session->UserID > 0)
    $WhosOnline->UpdateDateLastActive();
    else
    $WhosOnline->UpdateGuestLastActive();
    }

    if (in_array($Context->SelfUrl, array("account.php", "categories.php", "comments.php", "index.php", "post.php", "search.php", "settings.php"))
    && $Context->Session->UserID > 0 && !$Context->Session->User->Preference("HideWhosOnline")) {
    $ListName = $Context->GetDefinition("Who's Online");
    $Panel->AddList($ListName);
    $online_list = $WhosOnline->GetWhosOnline();
    $guest_count = $WhosOnline->GetGuestCount();
    $phantom_count = 0;
    if ($online_list) {
    foreach ($online_list as $name) {
    if ($name["Phantom"]) {
    $phantom_count++;
    }
    if (!$name["Phantom"] || !isset($name["Phantom"]) || $Context->Session->User->Permission("PERMISSION_WHOS_PHANTOM")) {
    $TimePast = TimeDiff($Context, unixtimestamp($name["DateLastActive"]));
    $Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), "account.php?u=" . $name["UserID"],NULL,"title=\"$TimePast\"");
    }
    }
    if ($phantom_count > 0) {
    $phantom_string = "$phantom_count phantom user";
    if ($phantom_count > 1)
    $phantom_string .= "s";
    $Panel->AddListItem($ListName,'','',$phantom_string);
    }
    if ($guest_count > 0) {
    $guest_string = "$guest_count guest";
    if ($guest_count > 1)
    $guest_string .= "s";
    $Panel->AddListItem($ListName,'','',$guest_string);
    }
    } else {
    $Panel->AddListItem($ListName,'','',"Nobody's online.");
    }
    }

    // Add the Who's Online setting to the forum preferences form
    if ($Context->SelfUrl == "account.php" && $Context->Session->UserID > 0) {
    $PostBackAction = ForceIncomingString("PostBackAction", "");
    if ($PostBackAction == "Functionality") {
    function PreferencesForm_AddWhosOnlinePreference(&$PreferencesForm) {
    $PreferencesForm->AddPreference("MenuOptions", "HideWhosOnline", "HideWhosOnline", 0);
    $PreferencesForm->AddPreference("MenuOptions", "Phantom", "Phantom", 0);
    }

    $Context->AddToDelegate("PreferencesForm",
    "Constructor",
    "PreferencesForm_AddWhosOnlinePreference");
    }
    }


    ?>

    Could you please point out where to hack the code? Thank.
  • Look for the//////////// lines, its the code between those.
    <?php /* Extension Name: Who's Online Extension Url: http://www.thirty5.net/code/vanilla/whosonline/ Description: Adds a "who's online" list to the panel. Version: 1.2 Author: David Knowles, Julien Cassignol, Michael Schieben Author Url: mailto:dknowles2@gmail.com Additional Author: Michael Schieben - michael@twoantennas.com (Adaption to Vanilla 1.0) */ class WhosOnline { var $Name; var $Context; function WhosOnline(&$Context) { $this->Name = "WhosOnline"; $this->Context = &$Context; } function GetWhosOnline() { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); $s->SetMainTable("User", "u"); $s->AddSelect(array("Name", "UserID", "DateLastActive", "Preferences"), "u"); $s->AddWhere("u", "DateLastActive", "", "DATE_SUB(NOW(), INTERVAL 5 MINUTE)", ">=", NULL, NULL, 0); $result = $this->Context->Database->Select($s, $this->Name, "GetRecentUsers", "An error occurred while attempting to retrieve the requested information."); if ($this->Context->Database->RowCount($result) == 0) { return NULL; } else { $my_array = array(); while ($rows = $this->Context->Database->GetRow($result)) { if ($rows["Preferences"]) { $settings = unserialize($rows["Preferences"]); if (array_key_exists("Phantom", $settings)) $phantom = ForceBool($settings["Phantom"], 0); else $phantom = false; } else { $phantom = false; } array_push($my_array, array("Name" => $rows["Name"], "UserID" => $rows["UserID"], "DateLastActive" => $rows["DateLastActive"], "Phantom" => $phantom)); } return $my_array; } } function GetGuestCount() { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); $s->SetMainTable("IpHistory", "i"); $s->AddSelect("IpHistoryID", "i", "GuestCount", "COUNT"); $s->AddWhere("i", "UserID", "", 0, "="); $s->AddWhere("i", "DateLogged", "", "DATE_SUB(NOW(), INTERVAL 1 MINUTE)", ">=", 'and', NULL, 0); $result = $this->Context->Database->Select($s, $this->Name, "GetGuestCount", "An error occurred while attempting to retrieve the requested information."); $row = $this->Context->Database->GetRow($result); return $row["GuestCount"]; } function GetNextIpLetter($my_ip) { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); $s->SetMainTable("IpHistory", "i"); $s->AddSelect("RemoteIp", "i"); $s->AddWhere("i", "UserID", "", 0, "="); $s->AddWhere("i", "RemoteIp", "", "$my_ip([a-z])*$", "regexp"); $s->AddWhere("i", "DateLogged", "", "DATE_SUB(NOW(), INTERVAL 30 MINUTE)", ">=", 'and', NULL, 0); $s->AddOrderBy("RemoteIp", "i", "desc"); $s->AddLimit(0, 1); $result = $this->Context->Database->Select($s, $this->Name, "UpdateGuestLastActive", "An error occurred while logging user data."); if ($this->Context->Database->RowCount($result) > 0) { $row = $this->Context->Database->GetRow($result); if (preg_match("/([a-z])+$/", $row["RemoteIp"], $ip_letter)) return ++$ip_letter[0]; else return "a"; } else { return ""; } } function GetIpHistoryID($my_ip) { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); $s->SetMainTable("IpHistory", "i"); $s->AddSelect("IpHistoryID", "i"); $s->AddWhere("i", "UserID", "", 0, "="); $s->AddWhere("i", "RemoteIp", "", $my_ip, "="); $s->AddOrderBy("IpHistoryID", "i", "desc"); $s->AddLimit(0, 1); $result = $this->Context->Database->Select($s, $this->Name, "GetIpHistoryID", "An error occurred while attempting to retrieve the requested information."); $row = $this->Context->Database->GetRow($result); return $row["IpHistoryID"]; } function UpdateDateLastActive() { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); if (isset($_COOKIE['IpHistoryID'])) { $s->SetMainTable("IpHistory", "i"); $s->AddWhere("i", "IpHistoryID", "", $_COOKIE['IpHistoryID'], "="); $this->Context->Database->Delete($s, $this->Name, "UpdateDateLastActive", "An error occurred while deleting guest profile"); setcookie('IpHistoryID', '', time() - 3600); } $s->Clear(); $s->SetMainTable("User", "u"); $s->AddFieldNameValue("DateLastActive", "now()", 0); $s->AddWhere("u", "UserID", "", $this->Context->Session->UserID, "="); $result = $this->Context->Database->Update($s, $this->Name, "UpdateDateLastActive", "An error occurred while updating your account."); } function UpdateGuestLastActive() { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); if (isset($_COOKIE['IpHistoryID'])) { $s->Clear(); $s->SetMainTable("IpHistory", "i"); $s->AddFieldNameValue("DateLogged", "now()", 0); $s->AddWhere("i", "IpHistoryID", "", $_COOKIE['IpHistoryID'], "="); $result = $this->Context->Database->Update($s, $this->Name, "UpdateGuestLastActive", "An error occurred while logging user data."); } else { $my_ip = GetRemoteIp(1); $ip_letter = $this->GetNextIpLetter($my_ip); $s->Clear(); $s->SetMainTable("IpHistory", "i"); $s->AddFieldNameValue("UserID", 0); $s->AddFieldNameValue("RemoteIp", $my_ip . $ip_letter); $s->AddFieldNameValue("DateLogged", "Now()", 0); $this->Context->Database->Insert($s, $this->Name, "UpdateGuestLastActive", "An error occurred while logging user data."); setcookie('IpHistoryID', $this->GetIpHistoryID($my_ip . $ip_letter)); } } } /////////////////////////////////////////////////// $Head->AddStyleSheet('extensions/WhosOnline/style.css'); /////////////////////////////////////////////////// $WhosOnline = $Context->ObjectFactory->NewContextObject($Context, "WhosOnline"); if (!in_array($Context->SelfUrl, array("signin.php", "leave.php", "post.php", "passwordrequest.php", "passwordreset.php"))) { if ($Context->Session->UserID > 0) $WhosOnline->UpdateDateLastActive(); else $WhosOnline->UpdateGuestLastActive(); } //, "search.php", "settings.php""account.php", if (in_array($Context->SelfUrl, array("categories.php", "index.php", "post.php", "comments.php")) && $Context->Session->UserID > 0 && !$Context->Session->User->Preference("HideWhosOnline")) { $ListName = $Context->GetDefinition("Who's Online"); /////////////////////////////////////// $Panel->AddString("<div id='onlinenow'>",500); $Panel->AddList($ListName,501); //////////////////////////////////////// $online_list = $WhosOnline->GetWhosOnline(); $guest_count = $WhosOnline->GetGuestCount(); $phantom_count = 0; if ($online_list) { foreach ($online_list as $name) { if ($name["Phantom"]) { $phantom_count++; } if (!$name["Phantom"] || !isset($name["Phantom"]) || $Context->Session->User->Permission("PERMISSION_WHOS_PHANTOM")) { $TimePast = TimeDiff($Context, unixtimestamp($name["DateLastActive"])); $Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), "account.php?u=" . $name["UserID"],NULL,"title=\"$TimePast\""); } } if ($phantom_count > 0) { $phantom_string = "$phantom_count phantom user"; if ($phantom_count > 1) $phantom_string .= "s"; $Panel->AddListItem($ListName,'','',$phantom_string); } if ($guest_count > 0) { $guest_string = "$guest_count guest"; if ($guest_count > 1) $guest_string .= "s"; $Panel->AddListItem($ListName,'','',$guest_string); } } else { $Panel->AddListItem($ListName,'','',$Context->Dictionary['None online']); } ////////////////////////////////// $Panel->AddString("</div>",502); //////////////////////////////// } // Add the Who's Online setting to the forum preferences form /* if ($Context->SelfUrl == "account.php" && $Context->Session->UserID > 0) { $PostBackAction = ForceIncomingString("PostBackAction", ""); if ($PostBackAction == "Functionality") { function PreferencesForm_AddWhosOnlinePreference(&$PreferencesForm) { $PreferencesForm->AddPreference("MenuOptions", "HideWhosOnline", "HideWhosOnline", 0); $PreferencesForm->AddPreference("MenuOptions", "Phantom", "Phantom", 0); } $Context->AddToDelegate("PreferencesForm", "Constructor", "PreferencesForm_AddWhosOnlinePreference"); } } */ ?>
    And dont forget to make a style.css file in the WhosOnline folder with this contet:#onlinenow ul li ul { overflow:hidden; } #onlinenow ul li ul li { width:auto; margin-right:4px; float:left; }
  • Ok thanks..
    But the "who's online" has been moved to the bottom of the panel and still each user is show on a separate line!

    So right now it's like that:

    User one
    user two
    3 guest

    And all I'm looking for is:

    user one, user two etc.
    3guest

    :)

    btw, there's a style.css file in the extension folder, thanks.

    ***Edit***
    Never mind, I've this code in my vanilla.css file:
    ol,ul,li {
    list-style:none;
    margin:0;
    padding:0;
    }
    #Panel ul li {
    width:200px !important;
    line-height:24px;
    padding:0 !important;
    }

    And I think that's what causing the problem! :(
  • so now it works?
  • Yes thanks, it works fine.
  • I want to make the same mod as sjeeps, I've put the last code from Mr Do, but it´s still showing the list like user online.

    I've created the style.css but....what can I make?
  • Mr Do's hack works fine for me. Did you put style.css in the WhosOnline folder?

    I was wondering, would there be a way to add a character in order to separated users' names? Like a comma or something. It would be useful for users with a space in ther name.
  • sure, many ways. 1. make a small image of a comma and put it as background image no repeat on right on the #Panel ul li OR you can go into the code and hack some more, probably by changing the line $Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), "account.php?u=" . $name["UserID"],NULL,"title=\"$TimePast\"");to$Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]).", ", "account.php?u=" . $name["UserID"],NULL,"title=\"$TimePast\"");Notice the difference is : .", "
  • Yes I put the style.css and so, but.... no response from the script.
  • @chimera: Not sure what to say budd. You need to discribe your situation better. In the whosonline folder, are there 2 files (default.php and styles.css)? Does the style file have this code it in: #onlinenow ul li ul { overflow:hidden; } #onlinenow ul li ul li { width:auto; margin-right:4px; float:left; }
    did you add/change all of the following 4 lines to the default.php file:$Head->AddStyleSheet('extensions/WhosOnline/style.css'); $Panel->AddString("<div id='onlinenow'>",500); $Panel->AddList($ListName,501); $Panel->AddString("</div>",502);
    If you have still problems, whisper me an url so I can see your page
  • Thanks, changing the line works fine. However, the character is displayed even if the user is the last of the list. Looks like it's a pain to change this, so for now I've put a period instead of the comma :)
  • clever boy :P
  • I was having some problems with this working nicely with Friendly URL extension. When already in the account section (http://www.fngeeks.net/vanilla/account/) and then clicking on someone's name under Who's Online, I'd recieve a 404 File Not Found Error Message because it couldn't find the URL http://www.fngeeks.net/vanilla/account/account.php?u=2

    They way I got it to work was with the following:

    Edit: Deleted code. Found out the proper way to do it.
Sign In or Register to comment.