Posts: 15,164
Threads: 241
Joined: Jun 2009
Reputation:
700
Ok, all done. I've left the dates and times in the UNIX timestamp format as it's the easiest way to compare dates and stuff anyway. If you want them converting to a readable format, just say.
<?php
header ("Content-Type:text/xml");
define("IN_MYBB", 1);
require_once "./global.php";
if($mybb->input['username'])
{
$user = $db->simple_select("users", "*", "username='".$mybb->input['username']."'");
$user = $db->fetch_array($user);
$usergroupcache = $cache->read("usergroups");
$doc = new DOMDocument();
$doc->formatOutput = true;
$u = $doc->createElement("user");
$doc->appendChild($u);
$uid = $doc->createElement("uid");
$uid->appendChild($doc->createTextNode($user['uid']));
$name = $doc->createElement("username");
$name->appendChild($doc->createTextNode($user['username']));
$usertitle = $doc->createElement("usertitle");
$usertitle->appendChild($doc->createTextNode($user['usertitle']));
$postcount = $doc->createElement("postcount");
$postcount->appendChild($doc->createTextNode($user['postnum']));
$usergroup = $doc->createElement("usergroup");
$usergroup->appendChild($doc->createTextNode($usergroupcache[$user['usergroup']]['title']));
$joindate = $doc->createElement("joindate");
$joindate->appendChild($doc->createTextNode($user['regdate']));
$numthreads = $db->simple_select("threads", "COUNT(tid) as count", "uid = ".$user['uid']);
$numthreads = $db->fetch_field($numthreads, "count");
$postedthreads = $doc->createElement("totalthreads");
$postedthreads->appendChild($doc->createTextNode($numthreads));
$referred = $doc->createElement("referred");
$referred->appendChild($doc->createTextNode($user['referrals']));
$timesearch = TIME_NOW - $mybb->settings['wolcutoffmins']*60;
$query = $db->simple_select("sessions", "location,nopermission", "uid='".$user['uid']."' AND time>'".$timesearch."'", array('order_by' => 'time', 'order_dir' => 'DESC', 'limit' => 1));
$session = $db->fetch_array($query);
if ($db->num_rows($query) == 0)
{
$onlinestatustext = "Offline";
}
else
{
require_once MYBB_ROOT."inc/functions_online.php";
$lang->load("online");
$location = fetch_wol_activity($session['location'], $session['nopermission']);
$location = build_friendly_wol_location($location);
$onlinestatustext = "Online - ".strip_tags($location);
}
$status = $doc->createElement("onlinestatus");
$status->appendChild($doc->createTextNode($onlinestatustext));
$lastvisit = $doc->createElement("lastvisit");
$lastvisit->appendChild($doc->createTextNode($user['lastvisit']));
$u->appendChild($uid);
$u->appendChild($name);
$u->appendChild($usertitle);
$u->appendChild($postcount);
$u->appendChild($usergroup);
$u->appendChild($joindate);
$u->appendChild($postedthreads);
$u->appendChild($referred);
$u->appendChild($status);
$u->appendChild($lastvisit);
echo $doc->saveXML();
}
?>
Posts: 41
Threads: 7
Joined: Jun 2011
Reputation:
0
Can you put Joindate in a date format? So I can just download it & put it in my program
& I want to compare the lastvisit with the date & time it is now.
How do I do that? I don't understand what it is now, lol.
This is what I get :
<user>
<uid>1</uid>
<username>SergeMorel</username>
<usertitle/>
<postcount>29</postcount>
<usergroup>Administrators</usergroup>
<joindate>1309005295</joindate>
<totalthreads>10</totalthreads>
<referred>5</referred>
<onlinestatus>Online - Unknown Location</onlinestatus>
<lastvisit>1310115706</lastvisit>
</user>
Also, why is it unknown location?
Thank you so much !
Posts: 9,406
Threads: 368
Joined: Aug 2009
Reputation:
116
Serge, to convert the timestamp use this:
Dim joindate As Double = 'INSERT TIMESTAMP HERE
‘Setup a new DateTime starting at Jan 1st 1970.
Dim joindateFormatted As New DateTime(1970, 1, 1)
‘
‘Then just add the Unix value to the DateTime variable as seconds.
joindateFormatted = joindateFormatted.AddSeconds(joindate)
Posts: 15,164
Threads: 241
Joined: Jun 2009
Reputation:
700
It's unknown location as you're accessing the script and it isn't officially a part of MyBB
For the last visit, I had a look, but it seems vb.net doesn't do UNIX timestamps quite correctly.
Posts: 9,406
Threads: 368
Joined: Aug 2009
Reputation:
116
To my knowledge vb.net handles unix timestamps fine  it just depends on your system time.
Posts: 41
Threads: 7
Joined: Jun 2011
Reputation:
0
(2011-07-08, 10:06 AM)Tom K. Wrote: Serge, to convert the timestamp use this:
Dim joindate As Double = 'INSERT TIMESTAMP HERE
‘Setup a new DateTime starting at Jan 1st 1970.
Dim joindateFormatted As New DateTime(1970, 1, 1)
‘
‘Then just add the Unix value to the DateTime variable as seconds.
joindateFormatted = joindateFormatted.AddSeconds(joindate)

that just gives me 1/01/1970 ?
Posts: 15,164
Threads: 241
Joined: Jun 2009
Reputation:
700
(2011-07-08, 10:12 AM)Tom K. Wrote: To my knowledge vb.net handles unix timestamps fine it just depends on your system time.
What I mean is that there's no simple function to create the current timestamp  There's also the epoch difference between unix and windows.
(2011-07-08, 10:14 AM)SergeMorel Wrote: (2011-07-08, 10:06 AM)Tom K. Wrote: Serge, to convert the timestamp use this:
Dim joindate As Double = 'INSERT TIMESTAMP HERE
‘Setup a new DateTime starting at Jan 1st 1970.
Dim joindateFormatted As New DateTime(1970, 1, 1)
‘
‘Then just add the Unix value to the DateTime variable as seconds.
joindateFormatted = joindateFormatted.AddSeconds(joindate)

that just gives me 1/01/1970 ?
That's the epoch  I'm converting the timestamps to dates for you in the below script:
<?php
header ("Content-Type:text/xml");
define("IN_MYBB", 1);
require_once "./global.php";
require_once "./inc/functions_time.php";
if($mybb->input['username'])
{
$user = $db->simple_select("users", "*", "username='".$mybb->input['username']."'");
$user = $db->fetch_array($user);
$usergroupcache = $cache->read("usergroups");
$doc = new DOMDocument();
$doc->formatOutput = true;
$u = $doc->createElement("user");
$doc->appendChild($u);
$uid = $doc->createElement("uid");
$uid->appendChild($doc->createTextNode($user['uid']));
$name = $doc->createElement("username");
$name->appendChild($doc->createTextNode($user['username']));
$usertitle = $doc->createElement("usertitle");
$usertitle->appendChild($doc->createTextNode($user['usertitle']));
$postcount = $doc->createElement("postcount");
$postcount->appendChild($doc->createTextNode($user['postnum']));
$usergroup = $doc->createElement("usergroup");
$usergroup->appendChild($doc->createTextNode($usergroupcache[$user['usergroup']]['title']));
$joindate = $doc->createElement("joindate");
$joindate->appendChild($doc->createTextNode(my_date($mybb->settings['dateformat'], $user['regdate'])));
$numthreads = $db->simple_select("threads", "COUNT(tid) as count", "uid = ".$user['uid']);
$numthreads = $db->fetch_field($numthreads, "count");
$postedthreads = $doc->createElement("totalthreads");
$postedthreads->appendChild($doc->createTextNode($numthreads));
$referred = $doc->createElement("referred");
$referred->appendChild($doc->createTextNode($user['referrals']));
$timesearch = TIME_NOW - $mybb->settings['wolcutoffmins']*60;
$query = $db->simple_select("sessions", "location,nopermission", "uid='".$user['uid']."' AND time>'".$timesearch."'", array('order_by' => 'time', 'order_dir' => 'DESC', 'limit' => 1));
$session = $db->fetch_array($query);
if ($db->num_rows($query) == 0)
{
$onlinestatustext = "Offline";
}
else
{
require_once MYBB_ROOT."inc/functions_online.php";
$lang->load("online");
$location = fetch_wol_activity($session['location'], $session['nopermission']);
$location = build_friendly_wol_location($location);
$onlinestatustext = "Online - ".strip_tags($location);
}
$status = $doc->createElement("onlinestatus");
$status->appendChild($doc->createTextNode($onlinestatustext));
$lastvisit = $doc->createElement("lastvisit");
$lastvisit->appendChild($doc->createTextNode(my_date($mybb->settings['dateformat'], $user['lastvisit'])));
$u->appendChild($uid);
$u->appendChild($name);
$u->appendChild($usertitle);
$u->appendChild($postcount);
$u->appendChild($usergroup);
$u->appendChild($joindate);
$u->appendChild($postedthreads);
$u->appendChild($referred);
$u->appendChild($status);
$u->appendChild($lastvisit);
echo $doc->saveXML();
}
?>
Posts: 9,406
Threads: 368
Joined: Aug 2009
Reputation:
116
Have you inserted the timestamp?
Also, this returns a UTC/GMT based time, so you might have to account for some differences in timezone
Posts: 41
Threads: 7
Joined: Jun 2011
Reputation:
0
2011-07-08, 10:22 AM
(This post was last modified: 2011-07-08, 10:25 AM by SergeMorel.)
is this the timestamp ?
1309005295
I'll do it like this
Check the lastvisit, if it's not 'Today', then get a msgbox they need to be more active on the forum.
I used your last script & now it gives 'Today' or a date.
That's very sweet. Thank you for everything !!!
The only thing I need to figure out is login with special characters
Posts: 15,164
Threads: 241
Joined: Jun 2009
Reputation:
700
Yes, that's a timestamp.
Also, I just fixed a small issue with the script that occurs if there's an invalid username.
<?php
header ("Content-Type:text/xml");
define("IN_MYBB", 1);
require_once "./global.php";
require_once "./inc/functions_time.php";
$user = $db->simple_select("users", "*", "username='".$mybb->input['username']."'");
if($mybb->input['username'] && $db->num_rows($user) != 0)
{
$user = $db->fetch_array($user);
$usergroupcache = $cache->read("usergroups");
$doc = new DOMDocument();
$doc->formatOutput = true;
$u = $doc->createElement("user");
$doc->appendChild($u);
$uid = $doc->createElement("uid");
$uid->appendChild($doc->createTextNode($user['uid']));
$name = $doc->createElement("username");
$name->appendChild($doc->createTextNode($user['username']));
$usertitle = $doc->createElement("usertitle");
$usertitle->appendChild($doc->createTextNode($user['usertitle']));
$postcount = $doc->createElement("postcount");
$postcount->appendChild($doc->createTextNode($user['postnum']));
$usergroup = $doc->createElement("usergroup");
$usergroup->appendChild($doc->createTextNode($usergroupcache[$user['usergroup']]['title']));
$joindate = $doc->createElement("joindate");
$joindate->appendChild($doc->createTextNode(my_date($mybb->settings['dateformat'], $user['regdate'])));
$numthreads = $db->simple_select("threads", "COUNT(tid) as count", "uid = ".$user['uid']);
$numthreads = $db->fetch_field($numthreads, "count");
$postedthreads = $doc->createElement("totalthreads");
$postedthreads->appendChild($doc->createTextNode($numthreads));
$referred = $doc->createElement("referred");
$referred->appendChild($doc->createTextNode($user['referrals']));
$timesearch = TIME_NOW - $mybb->settings['wolcutoffmins']*60;
$query = $db->simple_select("sessions", "location,nopermission", "uid='".$user['uid']."' AND time>'".$timesearch."'", array('order_by' => 'time', 'order_dir' => 'DESC', 'limit' => 1));
$session = $db->fetch_array($query);
if ($db->num_rows($query) == 0)
{
$onlinestatustext = "Offline";
}
else
{
require_once MYBB_ROOT."inc/functions_online.php";
$lang->load("online");
$location = fetch_wol_activity($session['location'], $session['nopermission']);
$location = build_friendly_wol_location($location);
$onlinestatustext = "Online - ".strip_tags($location);
}
$status = $doc->createElement("onlinestatus");
$status->appendChild($doc->createTextNode($onlinestatustext));
$lastvisit = $doc->createElement("lastvisit");
$lastvisit->appendChild($doc->createTextNode(my_date($mybb->settings['dateformat'], $user['lastvisit'])));
$u->appendChild($uid);
$u->appendChild($name);
$u->appendChild($usertitle);
$u->appendChild($postcount);
$u->appendChild($usergroup);
$u->appendChild($joindate);
$u->appendChild($postedthreads);
$u->appendChild($referred);
$u->appendChild($status);
$u->appendChild($lastvisit);
echo $doc->saveXML();
}
else
{
error("invalid user");
}
?>
|