3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Object\Api\Twitter;
24 use Friendica\BaseDataTransferObject;
25 use Friendica\Content\ContactSelector;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Core\Protocol;
28 use Friendica\Model\Contact;
29 use Friendica\Util\DateTimeFormat;
30 use Friendica\Util\Proxy;
33 * @see https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/user-object
35 class User extends BaseDataTransferObject
44 protected $screen_name;
45 /** @var string|null */
49 /** @var string|null */
53 /** @var string|null */
54 protected $description;
60 protected $followers_count;
62 protected $friends_count;
64 protected $listed_count;
66 protected $favourites_count;
68 protected $statuses_count;
70 protected $created_at;
72 protected $profile_banner_url;
74 protected $profile_image_url_https;
76 protected $default_profile;
78 protected $default_profile_image;
82 protected $withheld_in_countries;
84 protected $withheld_scope;
89 * - profile_sidebar_fill_color
90 * - profile_link_color
91 * - profile_background_color
95 * @param array $publicContact Full contact table record with uid = 0
96 * @param array $apcontact Optional full apcontact table record
97 * @param array $userContact Optional full contact table record with uid != 0
98 * @param bool $skip_status Whether to remove the last status property, currently unused
99 * @param bool $include_user_entities Whether to add the entities property
100 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
102 public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $status = null, $include_user_entities = true)
104 $uid = $userContact['uid'] ?? 0;
106 $this->id = (int)$publicContact['id'];
107 $this->id_str = (string) $publicContact['id'];
108 $this->name = $publicContact['name'] ?: $publicContact['nick'];
109 $this->screen_name = $publicContact['nick'] ?: $publicContact['name'];
110 $this->location = $publicContact['location'] ?:
111 ContactSelector::networkToName($publicContact['network'], $publicContact['url'], $publicContact['protocol']);
113 $this->url = $publicContact['url'];
114 // No entities needed since we don't perform any shortening in the URL or description
116 'url' => ['urls' => []],
117 'description' => ['urls' => []],
119 if (!$include_user_entities) {
120 unset($this->entities);
122 $this->description = (!empty($publicContact['about']) ? BBCode::toPlaintext($publicContact['about']) : '');
123 $this->profile_image_url_https = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
124 $this->protected = false;
125 $this->followers_count = $apcontact['followers_count'] ?? 0;
126 $this->friends_count = $apcontact['following_count'] ?? 0;
127 $this->listed_count = 0;
128 $this->created_at = DateTimeFormat::utc($publicContact['created'], DateTimeFormat::API);
129 $this->favourites_count = 0;
130 $this->verified = $uid != 0;
131 $this->statuses_count = $apcontact['statuses_count'] ?? 0;
132 $this->profile_banner_url = Contact::getHeaderUrlForId($publicContact['id'], '', $publicContact['updated']);
133 $this->default_profile = false;
134 $this->default_profile_image = false;
136 if (!empty($status)) {
137 $this->status = $status;
139 unset($this->status);
142 // Unused optional fields
143 unset($this->withheld_in_countries);
144 unset($this->withheld_scope);
147 $this->profile_image_url = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
148 $this->profile_image_url_profile_size = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_THUMB);
149 $this->profile_image_url_large = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_LARGE);
150 $this->utc_offset = 0;
151 $this->time_zone = 'UTC';
152 $this->geo_enabled = false;
154 $this->contributors_enabled = false;
155 $this->is_translator = false;
156 $this->is_translation_enabled = false;
157 $this->following = in_array($userContact['rel'] ?? Contact::NOTHING, [Contact::FOLLOWER, Contact::FRIEND]);
158 $this->follow_request_sent = false;
159 $this->statusnet_blocking = false;
160 $this->notifications = false;
162 // Friendica-specific
163 $this->uid = (int)$uid;
164 $this->cid = (int)($userContact['id'] ?? 0);
165 $this->pid = (int)$publicContact['id'];
166 $this->statusnet_profile_url = $publicContact['url'];