OpenSim.VisitorBoard/classes/GridUserInfo.php

348 lines
26 KiB
PHP
Raw Permalink Normal View History

2020-11-28 08:19:59 +00:00
<?php
/***********************************************************************
* Script (c) Kubwa (https://kubwa.de)
*
* This script was release under BSD license.
* You are free to use, share or change this code as you wish. This
* header must be kept intact.
***********************************************************************/
class GridUser
{
//Predfined images
private $ErrorImage = "/9j/4AAQSkZJRgABAQEAYABgAAD/4QBoRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAARAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMi4xMAAA/9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgBAAEAAwEhAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A+y6KACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACkoAhmvre3VmlnjjCjJLMBgVjy+PvDUDbZNf01G9GukH9aALVn4r0XUmAtdVs7g+kU6t/I1pJKkn3HVvoc0APooAKKACigAooAKKACigAooAKKACigAooAKKACigAqC8vrfT7d57qaO3hQZaSRgoH4mgDxzxl+05o2jtJb6LA2qzrkeafliB/ma8X8SfHTxd4klctqJsYWGPJsxsUfj1/WgDiLvVLy/kMlzdTTuerSSFj+tVtxPU5oAVZGXoxH0NbGk+NNd0Jw1jqt1b46BZTj8qAPTvCP7Tuu6SyRazDHqtv0MgGyUD6jg/lXvPgj4seHvHkYFjeLFdgZa1n+WQfQd/woA7KigAooAKKACigAooAKKACigAooAKKACigAooA5L4hfErSfh5prT30u+6YfubVOXkP9B7mvkvx/wDFTW/iBeM95OYbMH93aQkhFHv6mgDjaKACigAooAKkt7mWzmWWCRopVOVdDgigD3r4U/tFzWbQaX4mczQZ2pffxL/v+o96+kLW6hvbeOeCRZoZBuV0OQR6g0AS0UAFFABRQAUUAFFABRQAUUAFFABRQAVyPxK+IVl8PPDst7OyvdMNtvb55kb/AAHU0AfGHibxNf8Ai3V59R1Gdpp5GzyeFHYAdhWTQA+GGS4lWOJGkkY4CqMk16t4J/Zz8Q+Jo1ub8ro9o3K+cMyN9F7fjQB63on7MfhTTwpvWudScdQ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w4t7rH76/keZ+OQAdoH5DP416pQAUUAJXgHxy+OQsRP4f8Pz/wCk8pc3cZ+56qp9fegD5tZi7FmJZicknvSUAekfCP4QXnxEvhcTBrbR4WHmTEH95/sr719faPo9poOnQWNjAlvbQqFVEGP8mgC7Xxf8etFXRfiVqQRQqXG2cAD+8Of1zQB55Xt37K+qG38W6hZZ+We23Y91I/xoA+paKACigAooAKKACigAooAKKACuU+Klw1t8OfELqASbORefdSP60AfC9FAH3X8MIxD8PfD6qAB9jj6f7orqKACk6daAPAPjn8chYrP4f0CbNx9y5u4z9z1VT6+9fNrMXYsxLMTkk96AEr0f4Q/CK7+Imoie4D2+jQt+9mxjzP8AYX3/AJUAfYGkaTa6HpsFjZQrBbQqERFGABVygAr5X/aqhWPxtp8gABeyGffDtQB4pXqn7NczR/E23VekkEit9MZ/pQB9f0UAFFABRQAUUAFFABRQAUUAFcx8Trb7X8PfEMff7FKwx7KT/SgD4TooA+5fhLfR6h8N9AlibcotUjP+8o2n9Qa66gBM45PArwD45/HIWKz+HtAmzcH5Lm8jP3PVVPr6mgD5tZi7FmJZicknvSUAeifCT4R3nxE1ISyh7bSIWHmz4+//ALK+/wDKvsHRtGtNA02CxsYVt7aFdqoooAvUUAFfKH7Ul4lx4+tol6wWaq31LMf5EUAeN16v+zTbtN8SonHSO3kY/kB/WgD68ooAKKACigAooAKKACigAooAKhvLdLq0mhkVXSRCrKwyCCOhoA/P/WtPfSdYvbKTG+3meM46cEiqVAH1T+y74jGoeD7nSnfMljMSik/wNz/PP517STjk8CgDwD45fHIWSz+H9AmDTkbLm7jP3
private $BlockedImage = "/9j/4AAQSkZJRgABAQEAYABgAAD/4QBoRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAExAAIAAAARAAAATgAAAAAAAABgAAAAAQAAAGAAAAABcGFpbnQubmV0IDQuMi4xMAAA/9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgBAAEAAwEhAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A+y6KACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigAooAKKACigArzzx58cvDfgVpLd5m1LUl4+yWmCVP8AtN0X+ftQB43rP7VXiK6Zhp2n2VhH2MgaVx+OQP0rBH7R/joSbv7SgI/u/ZI8fyzQB0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QAUUAFFAFXVNSt9H065vruQRW1vG0sjnsoGTXwz8QPGVz488VXmrXBYLI22GJjny4x91fy6+5NAHOUUAFFABRQBf0DRLrxJrVnpdlH5l1dSiJF+vc+wGSfYV90+DfCdn4K8O2ek2KBY4F+Z8cyOeWY+5NAFD4jfEKw+HPh+TULw+ZO2UtrZT80r46ew9T2r408ZeNtW8d6vJqGq3Blc8RxLxHEvZVHb+tADvBfgXV/H2pPZaRCkssa75DJIEVFzjJzzj6CvZNJ/ZKnkt1bU/EMcM3eO1ti6j/gTMM/lQBFrX7Jd7DCX0rX4bmXtFdQGIH/AIEpb+VeReL/AIf694FuFi1iwktlc4jmHzRv9GHH4daALXw9+JWrfDnVRc2EpktXIE9nIf3cq/0PoRX2Z4P8Xaf430G31XTZC8EowyNw0bDqrD1FAG3RQAUUAFFABRQAUUAFFABRQB4V+1H42bTdDtPDts+2W+Pm3BB58pTwv4t/6D718w0AFFAB
private $Uuid;
private $HomeUri;
private $FirstName;
private $LastName;
private $HomeGrid;
private $BirthUnix;
private $ServiceUris;
private $ProfileImageUuid;
private $ProfileImageBlob;
private $ProfileAbout;
private $LastRequest;
private $LastUpdate;
private $UserTitle;
private $HomeRegionUuid;
private $HomeRegionName;
private $HomeRegionUri;
private $HomeRegionPos;
private $OSHeaders = array();
private $MySql;
2020-12-07 17:00:06 +00:00
public function __construct($Uuid, $HomeUri)
2020-11-28 08:19:59 +00:00
{
if (empty($Uuid) || empty($HomeUri))
{return;}
$this->Uuid = $Uuid;
$this->HomeUri = $HomeUri;
$this->MySql = new MySql($GLOBALS["CONFIG"]["mysql"]["user"], $GLOBALS["CONFIG"]["mysql"]["pass"], $GLOBALS["CONFIG"]["mysql"]["db"], $GLOBALS["CONFIG"]["mysql"]["server"]);
//Process OpenSim header fields
foreach ($_SERVER as $k => $v)
{
if (substr($k, 5, 13) == "X_SECONDLIFE_")
{$this->OSHeaders[substr($k, 18)] = $v;}
}
//Remove cached profile images after 60 days but process this cleanup every 5 days only
if ($this->HelpValue("IMAGE.LAST.CLEANTIME") + 86400 * 5 < time())
{
2020-12-07 17:00:06 +00:00
//Delete the cached metadata
2020-11-28 08:19:59 +00:00
$this->MySql->query("DELETE FROM userdata WHERE lastreq < {0}", array(time() - 86400 * 60));
}
//Do the magic
$this->LastRequest = time();
if ($this->ExistsInCache()) //User exists in cache?
{
$this->GetFromCache(); //Load everything from cache
if ($this->LastUpdate + 3600 * 4 < time())
{
$this->GetFromInternet(); //Get all the data from the users grid
if ($this->HomeGrid == "Unknown" &&
$this->FirstName == "Unknown" &&
$this->LastName == "User")
{$this->GetFromCache();}
}
}
else
{$this->GetFromInternet();}
}
//The user might be unwanted in our system. See mysql table "bans"
private function IsUnwanted($CheckList)
{
$AllBans = $this->MySql->query("SELECT * FROM bans");
while ($Ban = $AllBans->fetch())
{
for ($i = 0; $i < count($CheckList); ++$i)
{
if (stripos($CheckList[$i], $Ban["banvalue"]) !== false)
{
$this->MySql->query("UPDATE bans SET nums = {1}, lastseen = {2} WHERE banvalue = {0} LIMIT 1", array($Ban["banvalue"], $Ban["nums"] + 1, $this->OSHeaders["OBJECT_KEY"]));
return true;
}
}
}
return false;
}
private function ExistsInCache()
{
$InCache = $this->MySql->query("SELECT * FROM userdata WHERE id = {0} LIMIT 1", array($this->Uuid))->fetch();
return !empty($InCache["id"]);
}
private function GetFromCache()
{
$Cache = $this->MySql->query("SELECT * FROM userdata WHERE id = {0} LIMIT 1", array($this->Uuid))->fetch();
$this->FromJson($Cache["userdata"]);
$this->LastUpdate = $Cache["lastreq"];
2020-12-07 17:00:06 +00:00
$this->ProfileImageBlob = $Cache["image"];
2020-11-28 08:19:59 +00:00
}
//Magic function
private function GetFromInternet()
{
//First of all, we need to find out what uris the gridservices are having for this user (might be different for each user)
$this->ServiceUris = $this->RequestUserSeviceUris();
if ($this->ServiceUris !== false)
{
//IF this was successfull, we are requesting all required user info from the services
$UserInfo = $this->RequestUserInfo();
if ($UserInfo !== false)
{
$this->FirstName = $UserInfo["user_firstname"];
$this->LastName = $UserInfo["user_lastname"];
/* Ungewollte User in der Auflistung ausschließen */
if ($this->IsUnwanted(array($this->Uuid, $this->HomeUri, $this->FirstName." ".$this->LastName)))
{
$this->BirthUnix = 0;
$this->UserTitle = "Blacklisted";
$this->HomeGrid = "Somewhere";
$this->ProfileImageUuid = "00000000-0000-0000-0000-000000000001";
$this->ProfileAbout = "";
$this->HomeRegionUuid = "00000000-0000-0000-0000-000000000000";
$this->HomeRegionName = "";
$this->HomeRegionUri = "";
$this->HomeRegionPos = "";
$this->HomeRegionUuid = "00000000-0000-0000-0000-000000000000";
$this->HomeRegionName = "Unknown";
$this->HomeRegionUri = "";
$this->HomeRegionPos = "<0, 0, 0>";
$this->ProfileImageBlob = base64_decode($this->BlockedImage);
$this->AddToCache();
return;
}
//We can do more magic: Request the entire user profile, its image and all other cool stuff
$ProfileData = $this->RequestUserProfile();
$GridInfo = $this->RequestHomeGrid();
$this->BirthUnix = $UserInfo["user_created"];
$this->UserTitle = $UserInfo["user_title"];
if (empty($this->UserTitle))
{$this->UserTitle = "Unknown";}
$this->HomeGrid = $GridInfo["gridname"];
$this->ProfileImageUuid = $ProfileData["result"]["ImageId"];
$this->ProfileAbout = $ProfileData["result"]["AboutText"];
$HomeRegion = $this->RequestHomeRegion();
$this->HomeRegionUuid = $HomeRegion["uuid"];
$this->HomeRegionName = $HomeRegion["region_name"];
$this->HomeRegionUri = $HomeRegion["server_uri"];
$this->HomeRegionPos = $HomeRegion["position"];
$this->ProfileImageBlob = $this->RequestUserImageBlob();
$this->AddToCache();
return;
}
}
$this->FirstName = "Unknown";
$this->LastName = "User";
$this->BirthUnix = 0;
$this->UserTitle = "Wrong configured grid";
$this->HomeGrid = "Unknown";
$this->ProfileImageUuid = "00000000-0000-0000-0000-000000000000";
$this->ProfileAbout = "";
$this->HomeRegionUuid = "00000000-0000-0000-0000-000000000000";
$this->HomeRegionName = "";
$this->HomeRegionUri = "";
$this->HomeRegionPos = "";
$this->HomeRegionUuid = "00000000-0000-0000-0000-000000000000";
$this->HomeRegionName = "Unknown";
$this->HomeRegionUri = "";
$this->HomeRegionPos = "<0, 0, 0>";
2020-12-07 17:00:06 +00:00
$this->ProfileImageBlob = base64_decode($this->ErrorImage);
2020-11-28 08:19:59 +00:00
}
private function RequestUserSeviceUris()
{
$Res = HttpRequest($this->HomeUri, "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>get_server_urls</methodName><params><param><value><struct><member><name>userID</name><value><string>".$this->Uuid."</string></value></member></struct></value></param></params></methodCall>", "", 3, "application/xml");
if (strlen($Res) < 200)
{return false;}
$ServiceURLs = ParseXml($Res);
$ServiceURLList = array();
for ($i = 0; $i < count($ServiceURLs["params"]["param"]["value"]["struct"]["member"]); ++$i)
{
$ServiceURL = $ServiceURLs["params"]["param"]["value"]["struct"]["member"][$i];
$ServiceURLList[$ServiceURL["name"]] = $ServiceURL["value"]["string"];
}
if (count($ServiceURLList) < 7)
{return false;}
return $ServiceURLList;
}
private function RequestUserProfile()
{return json_decode(HttpRequest($this->ServiceUris["SRV_ProfileServerURI"], "{\"jsonrpc\":\"2.0\",\"id\":\"00000000-0000-0000-0000-000000000000\",\"method\":\"avatar_properties_request\",\"params\":{\"UserId\":\"".$this->Uuid."\"}}", "", 3, "application/json-rpc"), true);}
private function RequestUserInfo()
{
$UserInfos = ParseXml(HttpRequest($this->HomeUri, "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>get_user_info</methodName><params><param><value><struct><member><name>userID</name><value><string>".$this->Uuid."</string></value></member></struct></value></param></params></methodCall>", "", 3, "application/xml"));
$UserInfosList = array();
for ($i = 0; $i < count($UserInfos["params"]["param"]["value"]["struct"]["member"]); ++$i)
{
$UserInfo = $UserInfos["params"]["param"]["value"]["struct"]["member"][$i];
$UserInfosList[$UserInfo["name"]] = $UserInfo["value"]["string"]?$UserInfo["value"]["string"]:$UserInfo["value"]["i4"];
}
if (count($UserInfosList) < 6)
{return false;}
return $UserInfosList;
}
private function RequestHomeGrid()
{return ParseXml(HttpRequest($this->HomeUri.((substr($this->HomeUri, -1, 1) == "/")?"":"/")."get_grid_info", "", "", 3), true);}
private function RequestHomeRegion()
{
$HomeInfos = ParseXml(HttpRequest($this->HomeUri, "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodCall><methodName>get_home_region</methodName><params><param><value><struct><member><name>userID</name><value><string>".$this->Uuid."</string></value></member></struct></value></param></params></methodCall>", "", 3, "application/xml"));
$HomeInfosList = array();
for ($i = 0; $i < count($HomeInfos["params"]["param"]["value"]["struct"]["member"]); ++$i)
{
$HomeInfo = $HomeInfos["params"]["param"]["value"]["struct"]["member"][$i];
$HomeInfosList[$HomeInfo["name"]] = $HomeInfo["value"]["string"];
}
if (count($HomeInfosList) < 13)
{return false;}
return $HomeInfosList;
}
private function RequestUserImageBlob()
{
if (!empty($this->ProfileImageUuid) && $this->ProfileImageUuid != "00000000-0000-0000-0000-000000000000")
{
$AssetURI = $this->ServiceUris["SRV_AssetServerURI"].((substr($this->ServiceUris["SRV_AssetServerURI"], -1, 1) == "/")?"":"/")."assets/".$this->ProfileImageUuid."/data";
$AssetImageData = HttpRequest($AssetURI, "", "", 3);
$TempName = $this->MySql->id(8);
file_put_contents("binary_helper/".$TempName.".jp2", $AssetImageData);
if (extension_loaded("imagick"))
{
$Image = new Imagick(realpath("./binary_helper/".$TempName.".jp2"));
$Image->setImageFormat("jpg");
$Image->writeImage(realpath("./binary_helper/".$TempName.".jpg"));
}
else
{shell_exec("binary_helper".DIRECTORY_SEPARATOR."magick convert binary_helper/".$TempName.".jp2 binary_helper/".$TempName.".jpg");}
2020-11-28 08:19:59 +00:00
$AssetImageData = file_get_contents("binary_helper/".$TempName.".jpg");
@unlink("binary_helper/".$TempName.".jp2");
@unlink("binary_helper/".$TempName.".jpg");
if (strlen($AssetImageData) < 512)
{return base64_decode($this->ErrorImage);}
$SrcImg = imagecreatefromstring($AssetImageData);
$DstImg = ImageCreateTrueColor(200, 200);
imagecopyresampled($DstImg, $SrcImg, 0, 0, 0, 0, 200, 200, imageSX($SrcImg), imageSY($SrcImg));
ob_start();
imagejpeg($DstImg, null, 90);
$Res = ob_get_contents();
ob_end_clean();
}
else
{$Res = base64_decode($this->ErrorImage);}
return $Res;
}
private function AddToCache()
2020-12-07 17:00:06 +00:00
{$this->MySql->query("REPLACE INTO userdata(id, userdata, lastreq, image)VALUES({0}, {1}, {2}, {3})", array($this->Uuid, $this->ToJson(), $this->LastRequest, $this->ProfileImageBlob));}
2020-11-28 08:19:59 +00:00
public function ToArray($ExportImage = true)
2020-11-28 08:19:59 +00:00
{
if (!empty($this->FirstName))
{
$Export = array("uuid" => $this->Uuid,
"firstname" => $this->FirstName,
"lastname" => $this->LastName,
"homegrid" => $this->HomeGrid,
"birthunix" => $this->BirthUnix,
"profileimage" => $this->ProfileImageUuid,
"about" => $this->ProfileAbout,
"title" => $this->UserTitle,
"home" => $this->HomeRegionName,
"homelocation" => $this->HomeRegionPos,
"homeuri" => $this->HomeRegionUri);
if ($ExportImage)
{$Export["img"] = $this->ProfileImageBlob;}
return $Export;
2020-11-28 08:19:59 +00:00
}
else
{return false;}
}
public function ToJson()
{
if (!empty($this->FirstName))
{return json_encode($this->ToArray(false));}
2020-11-28 08:19:59 +00:00
else
{return false;}
}
public function FromJson($Json)
{
$Json = json_decode($Json, true);
$this->Uuid = $Json["uuid"];
$this->FirstName = $Json["firstname"];
$this->LastName = $Json["lastname"];
$this->HomeGrid = $Json["homegrid"];
$this->BirthUnix = $Json["birthunix"];
$this->ProfileImageUuid = $Json["profileimage"];
$this->ProfileAbout = $Json["about"];
$this->UserTitle = $Json["title"];
$this->HomeRegionName = $Json["home"];
$this->HomeRegionPos = $Json["homelocation"];
$this->HomeRegionUri = $Json["homeuri"];
}
public function ToLsl($Glue)
{
if (!empty($this->FirstName))
{
return implode($Glue, array($this->Uuid,
$this->FirstName,
$this->LastName,
($this->HomeGrid==null)?"Unknown":$this->HomeGrid,
($this->BirthUnix==null)?"0":$this->BirthUnix,
($this->ProfileImageUuid==null)?"00000000-0000-0000-0000-000000000000":$this->ProfileImageUuid,
base64_encode($this->ProfileAbout),
($this->UserTitle==null)?"":(is_array($this->UserTitle)?"":$this->UserTitle),
($this->HomeRegionName==null)?"":$this->HomeRegionName,
($this->HomeRegionPos==null)?"<0, 0, 0>":$this->HomeRegionPos,
($this->HomeRegionUri==null)?"":$this->HomeRegionUri));
}
else
{return false;}
}
private function HelpValue($Name, $Value = null)
{
if ($Value === null)
{
$Res = $this->MySql->query("SELECT * FROM helpvals WHERE name = {0} LIMIT 1", array($Name))->fetch();
return $Res["val"];
}
else
{$this->MySql->query("REPLACE INTO helpvals (name, val)VALUES({0}, {1})", array($Name, $Value));}
}
}
?>