295 lines
5.8 KiB
PHP
295 lines
5.8 KiB
PHP
<?php
|
|
namespace ContentNation\ActivityPub\Common;
|
|
|
|
class User {
|
|
/**
|
|
* User name
|
|
* @var string
|
|
*/
|
|
private $userName = '';
|
|
|
|
/**
|
|
* Account name
|
|
* @var string
|
|
*/
|
|
private $accountName = '';
|
|
|
|
/**
|
|
* Display name
|
|
* @var string
|
|
*/
|
|
private $displayName = '';
|
|
|
|
/**
|
|
* Locked flag
|
|
* @var bool
|
|
*/
|
|
private $locked = false;
|
|
|
|
/**
|
|
* Bot flag
|
|
* @var bool
|
|
*/
|
|
private $bot = false;
|
|
|
|
/**
|
|
* Discoverable flag
|
|
* @var bool
|
|
*/
|
|
private $discoverable = false;
|
|
|
|
/**
|
|
* Group flag
|
|
* @var bool
|
|
*/
|
|
private $group = false;
|
|
|
|
/**
|
|
* Created timestamp
|
|
* @var int
|
|
*/
|
|
private $created = 0;
|
|
|
|
/**
|
|
* Created note
|
|
* @var string
|
|
*/
|
|
private $note = '';
|
|
|
|
/**
|
|
* Created url
|
|
* @var string
|
|
*/
|
|
private $url = '';
|
|
|
|
/**
|
|
* Avatar URL
|
|
* @var string
|
|
*/
|
|
private $avatarURL = '';
|
|
/**
|
|
* headerURL
|
|
* @var string
|
|
*/
|
|
private $headerURL = '';
|
|
|
|
/**
|
|
* follower count
|
|
* @var int
|
|
*/
|
|
private $followerCount = 0;
|
|
|
|
/**
|
|
* status count
|
|
* @var int
|
|
*/
|
|
private $statusCount = 0;
|
|
|
|
/**
|
|
* last status timestamp
|
|
* @var int
|
|
*/
|
|
private $lastStatus = 0;
|
|
|
|
/**
|
|
* Field list (name, value verified)
|
|
* @var array<array<string,string,?string>>
|
|
*/
|
|
private $fields = [];
|
|
|
|
/**
|
|
* Set user name
|
|
* @param string $userName user name
|
|
* @return User current instance
|
|
*/
|
|
public function setUserName(string $userName) : User {
|
|
$this->userName = $userName;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set account name
|
|
* @param string $accountName account name
|
|
* @return User current instance
|
|
*/
|
|
public function setAccountName(string $accountName) : User {
|
|
$this->accountName = $accountName;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set display name
|
|
* @param string $displayName display name
|
|
* @return User current instance
|
|
*/
|
|
public function setDisplayName(string $displayName) : User {
|
|
$this->displayName = $displayName;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set locked status
|
|
* @param bool $locked locked status
|
|
* @return User current instance
|
|
*/
|
|
public function setLocked(bool $locked) : User {
|
|
$this->locked = $locked;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set bot status
|
|
* @param bool $bot bot status
|
|
* @return User current instance
|
|
*/
|
|
public function setBot(bool $bot) : User {
|
|
$this->bot = $bot;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set discoverable status
|
|
* @param bool $discoverable discoverable status
|
|
* @return User current instance
|
|
*/
|
|
public function setDiscoverable(bool $discoverable) : User {
|
|
$this->discoverable = $discoverable;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set group flag
|
|
* @param bool $group group flag
|
|
* @return User current instance
|
|
*/
|
|
public function setGroupFlag(bool $group) : User {
|
|
$this->group = $group;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set created timestamp
|
|
* @param int $timestamp timestamp
|
|
* @return User current instance
|
|
*/
|
|
public function setCreated(int $timestamp) : User {
|
|
$this->created = $timestamp;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set note
|
|
* @param string $note note
|
|
* @return User current instance
|
|
*/
|
|
public function setNote(string $note) : User {
|
|
$this->note = $note;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set URL
|
|
* @param string $url url
|
|
* @return User current instance
|
|
*/
|
|
public function setURL(string $url) : User {
|
|
$this->url = $url;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set avatar URL
|
|
* @param string $url url
|
|
* @return User current instance
|
|
*/
|
|
public function setAvatarURL(string $url) : User {
|
|
$this->avatarURL = $url;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set header URL
|
|
* @param string $url url
|
|
* @return User current instance
|
|
*/
|
|
public function setHeaderURL(string $url) : User {
|
|
$this->headerURL = $url;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set follower count
|
|
* @param int $count follower count
|
|
* @return User current instance
|
|
*/
|
|
public function setFollowerCount(int $count) : User {
|
|
$this->followerCount = $count;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set stats count
|
|
* @param int $count status count
|
|
* @return User current instance
|
|
*/
|
|
public function setStatusCount(int $count) : User {
|
|
$this->statusCount = $count;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Set last status timestamp
|
|
* @param int $timestamp status timestamp
|
|
* @return User current instance
|
|
*/
|
|
public function setLastStatus(int $timestamp) : User {
|
|
$this->lastStatus = $timestamp;
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Add field entry
|
|
* @param string $name field name
|
|
* @param string $value field value
|
|
* @param int $verified verified timestamp
|
|
* @return User current instance
|
|
*/
|
|
public function addField(string $name, string $value, int $verified) : User {
|
|
$this->fields[] = array(
|
|
"name" => $name,
|
|
"value" => $value,
|
|
"verified_at" => ($verified > 0) ? gmdate("Y-m-d\TH:i:S\Z", $verified) : null
|
|
);
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* convert internal state to php array
|
|
* @return array<string,mixed>
|
|
*/
|
|
public function toObject() {
|
|
$return = array(
|
|
"username" => $this->userName,
|
|
"acct" => $this->accountName,
|
|
"display_name" => $this->displayName,
|
|
"locked" => $this->locked,
|
|
"bot" => $this->bot,
|
|
"discoverable" => $this->discoverable,
|
|
"group" => $this->group,
|
|
"created_at" => gmdate("Y-m-d\TH:i:S\Z", $this->created),
|
|
"note" => $this->note,
|
|
"url" => $this->url,
|
|
"avatar" => $this->avatarURL,
|
|
"avatar_static" => $this->avatarURL,
|
|
"header" => $this->headerURL,
|
|
"header_static" => $this->headerURL,
|
|
"followers_count" => $this->followerCount,
|
|
"statuses_count" => $this->statusCount,
|
|
"emojis" => [],
|
|
"fields" => $this->fields
|
|
);
|
|
if ($this->lastStatus > 0) $return['last_status_at'] = gmdate("Y-m-d", $this->lastStatus);
|
|
return $return;
|
|
}
|
|
}
|