MyBB Community Forums

Full Version: Group php script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5
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();
}
?>
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? Smile

Thank you so much !
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)

Smile
It's unknown location as you're accessing the script and it isn't officially a part of MyBB Wink

For the last visit, I had a look, but it seems vb.net doesn't do UNIX timestamps quite correctly.
To my knowledge vb.net handles unix timestamps fine Smile it just depends on your system time.
(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)

Smile

that just gives me 1/01/1970 ?
(2011-07-08, 10:12 AM)Tom K. Wrote: [ -> ]To my knowledge vb.net handles unix timestamps fine Smile it just depends on your system time.

What I mean is that there's no simple function to create the current timestamp Wink 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)

Smile

that just gives me 1/01/1970 ?

That's the epoch Wink 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();
}
?>
Have you inserted the timestamp?

Also, this returns a UTC/GMT based time, so you might have to account for some differences in timezone Smile
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 Smile
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");
}
?>
Pages: 1 2 3 4 5