Skip to content

Instantly share code, notes, and snippets.

@katgirl
Created July 27, 2013 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katgirl/6094988 to your computer and use it in GitHub Desktop.
Save katgirl/6094988 to your computer and use it in GitHub Desktop.
XML-Output of User
<?php
class UserData extends \Frontend
{
public function __construct($intId, $strLanguage=null)
{
parent::__construct();
$this->import('Database');
}
protected function compile()
{
$user = \Input::get('user');
if ( $user === null )
{
$this->Template = new \Template('mod_message');
$this->Template->type = 'error';
$this->Template->message = $GLOBALS['TL_LANG']['ERR']['noUserGiven'];
return;
}
$objUser = \Database::getInstance()->prepare( "SELECT username, message_count, last_activity, user_state, alerts_unread, conversations_unread FROM xf_user WHERE username='?'" )->limit(1)->execute($user);
if (!$objUser->numRows)
{
throw new \UnderflowException('No UserData found by '.$user);
}
//Create XML
$dom = new DOMDocument('1.0', 'utf-8');
$root = $dom->createElement('UserData');
$dom->appendChild($root);
$root->appendChild($dom->createElement("username", $objUser->username));
$root->appendChild($dom->createElement("message_count", $objUser->message_count));
$root->appendChild($dom->createElement("last_activity", $objUser->last_activity));
$root->appendChild($dom->createElement("user_state", $objUser->user_state));
header('Content-type: text/xml; charset=utf-8');
echo $dom->saveXML();
}
}
$objUserData = new UserData;
$objUserData->compile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment