Alright, nix that. Went and researched this a bit more and NOW I think its working... I implemented the GetUrl() function so that it would handle both systems properly... I need someone to test this on a non-Friendly URL install.
I was trying to add color depending on role to the online users' list. I tried mimicking the dojo add-on, but can't seem to do it right Anyone care to help?
hm.. ok let me point you in the right direction. Ultimatly you should modify the getWhosOnline function to also retrieve the users role, I dont have time just now, but you need these lines: $q = "SELECT LUM_Role.Name FROM `LUM_User` LEFT JOIN `LUM_Role` USING (`RoleID`) WHERE UserID='".$Comment->AuthUserID."' LIMIT 1;";
$res = mysql_query($q);
$row = mysql_fetch_array($res);
$role = $row[0];
$role = str_replace(" ","",$role);
$role = strtolower($role); And then, on line 163 (my version anyway), this line:
$Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), "account.php?u=" . $name["UserID"],NULL,"title=\"$TimePast\""); Needs to be modified to add the class containing the color, like so:
$Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), "account.php?u=" . $name["UserID"],NULL,"title=\"$TimePast\" class=\"$role\""); Note, that you will also need to add a stylesheet for each role, by following the rules given in the Dojo Role Add On.
Thanks Mr. Do! You know, I was already doing the second part right!, which makes me kind of proud because I'm no good at this. The "retrieving" part, though, I really didn't know where to start, and now the problem is that just cutting and pasting won't do. I'm guessing this first line
$q = "SELECT LUM_Role.Name FROM `LUM_User` LEFT JOIN `LUM_Role` USING (`RoleID`) WHERE UserID='".$Comment->AuthUserID."' LIMIT 1;";
is the key. Would you give me some more clues on how to modify it?
ok here is what you do. Change GetWhosOnline function to this: function GetWhosOnline() {
$s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder");
$s->SetMainTable("User", "u");
$s->AddSelect(array("Name", "UserID", "DateLastActive", "Preferences","RoleID"), "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, "RoleID" => $rows['RoleID']));
}
return $my_array;
}
}Notice how I now retrieve the RoleID. Next step is to retrieve the Role names. You do this with these lines, that you place around line 160. Directly after the if ($online_list) { line: $q = "SELECT RoleID, Name FROM `LUM_Role`;";
$res = mysql_query($q); $role = array();
while ($row = mysql_fetch_array($res)) {
$tmp = $row[1];
$tmp = str_replace(" ","",$tmp);
$role[$row[0]] = strtolower($tmp);
}
Next step is change the add list like so: $Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), GetUrl($Context->Configuration, 'account.php', '', 'u', $name["UserID"]), NULL, "title=\"$TimePast\" class=\"".$role[$name['RoleID']]."\""); The css bit remains the same. Hope this gets you to the finish line
@skube: it is allready doing that. I mean its checking who was online in the last X minutes. There is no way for it to know who is reading a page at that exact moment. It checks for the last time it got a request from said user. It should be possible to do what you ask without much trouble
Unless you want something like a Settings preference, or a per-user preference, you can just edit the code of the extension. On line 31 it says $s->AddWhere("u", "DateLastActive", "", "DATE_SUB(NOW(), INTERVAL 5 MINUTE)", ">=", NULL, NULL, 0); Just change the 5 to the amount of minutes it should check for, or change 5 MINUTE into 1 DAY to get a whole day.
hi!
i noticed, that users who logged out are also seen as online until the 5 minute timeout.
how about adding an "is_online" column, which is also set to true in the UpdateDateLastActive() function.
after logout is_online is set to false.
in the GetWhosOnline() we add
date_sub(...) and is_online=true
how about this idea?
Any chance of someone packing all the enhancements/bugfixes up and making an unofficial release? Or better still, just getting it updated on the addons site
Ok to make whos online appear on pages that use postbackaction (ie PageMaker addon) you need to change the big if statement to this:
if ((in_array($Context->SelfUrl, array("categories.php", "index.php", "post.php", "comments.php")) && !isset($_GET['PageID']) || ($Context->SelfUrl == "index.php" && isset($_GET['PostBackAction'])))
&& $Context->Session->UserID > 0 && !$Context->Session->User->Preference("HideWhosOnline") ) { To make it show count when not signed in, add this code to the end of the file (outside all other methods / ifs):
if ((in_array($Context->SelfUrl, array("categories.php", "index.php", "comments.php")) && !isset($_GET['PageID']) )
&& $Context->Session->UserID == 0 ) {
$ListName = $Context->GetDefinition("Who's Online");
$Panel->AddList($ListName,501);
$online_list = $WhosOnline->GetWhosOnline();
$guest_count = $WhosOnline->GetGuestCount();
$phantom_count = 0;
$user_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")) {
$user_count++;
}
}
if ($user_count > 0) {
$user_string = "$user_count registered user";
if ($user_count > 1)
$user_string .= "s";
$Panel->AddListItem($ListName,'','',$user_string);
}
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']);
}
}
Just pop it on your own webspace and leave a link in here, then a mod can update the official one if they want. If you don't have spac eyou can pop it on, just email me and I'll host it.
Comments
EDIT: UPDATED AGAIN (4/30/07)
Find:
$Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), "account.php?u=" . $name["UserID"],NULL,"title=\"$TimePast\"");
Replace with:
$Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), GetUrl($Context->Configuration, 'account.php', '', 'u', $name["UserID"]), NULL, "title=\"$TimePast\"");
$q = "SELECT LUM_Role.Name FROM `LUM_User` LEFT JOIN `LUM_Role` USING (`RoleID`) WHERE UserID='".$Comment->AuthUserID."' LIMIT 1;"; $res = mysql_query($q); $row = mysql_fetch_array($res); $role = $row[0]; $role = str_replace(" ","",$role); $role = strtolower($role);
And then, on line 163 (my version anyway), this line:
$Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), "account.php?u=" . $name["UserID"],NULL,"title=\"$TimePast\"");
Needs to be modified to add the class containing the color, like so:
$Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), "account.php?u=" . $name["UserID"],NULL,"title=\"$TimePast\" class=\"$role\"");
Note, that you will also need to add a stylesheet for each role, by following the rules given in the Dojo Role Add On.
$q = "SELECT LUM_Role.Name FROM `LUM_User` LEFT JOIN `LUM_Role` USING (`RoleID`) WHERE UserID='".$Comment->AuthUserID."' LIMIT 1;";
is the key. Would you give me some more clues on how to modify it?
function GetWhosOnline() { $s = $this->Context->ObjectFactory->NewContextObject($this->Context, "SqlBuilder"); $s->SetMainTable("User", "u"); $s->AddSelect(array("Name", "UserID", "DateLastActive", "Preferences","RoleID"), "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, "RoleID" => $rows['RoleID'])); } return $my_array; } }
Notice how I now retrieve the RoleID. Next step is to retrieve the Role names. You do this with these lines, that you place around line 160. Directly after the if ($online_list) { line:$q = "SELECT RoleID, Name FROM `LUM_Role`;"; $res = mysql_query($q); $role = array(); while ($row = mysql_fetch_array($res)) { $tmp = $row[1]; $tmp = str_replace(" ","",$tmp); $role[$row[0]] = strtolower($tmp); }
Next step is change the add list like so:
$Panel->AddListItem($ListName, $Context->GetDefinition($name["Name"]), GetUrl($Context->Configuration, 'account.php', '', 'u', $name["UserID"]), NULL, "title=\"$TimePast\" class=\"".$role[$name['RoleID']]."\"");
The css bit remains the same. Hope this gets you to the finish line
I.E.
[ ] show currently online visitors
[ ] show everyone who visited in the last [15] mins
[ ] show everyone who visited today
$s->AddWhere("u", "DateLastActive", "", "DATE_SUB(NOW(), INTERVAL 5 MINUTE)", ">=", NULL, NULL, 0);
Just change the 5 to the amount of minutes it should check for, or change
5 MINUTE
into1 DAY
to get a whole day.if ((in_array($Context->SelfUrl, array("categories.php", "index.php", "post.php", "comments.php")) && !isset($_GET['PageID']) || ($Context->SelfUrl == "index.php" && isset($_GET['PostBackAction']))) && $Context->Session->UserID > 0 && !$Context->Session->User->Preference("HideWhosOnline") ) {
To make it show count when not signed in, add this code to the end of the file (outside all other methods / ifs):
if ((in_array($Context->SelfUrl, array("categories.php", "index.php", "comments.php")) && !isset($_GET['PageID']) ) && $Context->Session->UserID == 0 ) { $ListName = $Context->GetDefinition("Who's Online"); $Panel->AddList($ListName,501); $online_list = $WhosOnline->GetWhosOnline(); $guest_count = $WhosOnline->GetGuestCount(); $phantom_count = 0; $user_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")) { $user_count++; } } if ($user_count > 0) { $user_string = "$user_count registered user"; if ($user_count > 1) $user_string .= "s"; $Panel->AddListItem($ListName,'','',$user_string); } 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']); } }