3 * @copyright Copyright (C) 2010-2023, 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\Model\Contact;
28 use Friendica\Network\HTTPException\InternalServerErrorException;
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;
86 protected $profile_image_url;
88 protected $follow_request_sent;
90 protected $profile_image_url_large;
92 protected $profile_image_url_profile_size;
94 protected $utc_offset;
98 protected $geo_enabled;
102 protected $contributors_enabled;
104 protected $is_translator;
106 protected $is_translation_enabled;
108 protected $following;
110 protected $statusnet_blocking;
112 protected $notifications;
120 protected $statusnet_profile_url;
125 * - profile_sidebar_fill_color
126 * - profile_link_color
127 * - profile_background_color
131 * @param array $publicContact Full contact table record with uid = 0
132 * @param array $apcontact Optional full apcontact table record
133 * @param array $userContact Optional full contact table record with uid != 0
134 * @param null $status
135 * @param bool $include_user_entities Whether to add the entities property
137 * @throws InternalServerErrorException
139 public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $status = null, bool $include_user_entities = true)
141 $uid = $userContact['uid'] ?? 0;
143 $this->id = (int)$publicContact['id'];
144 $this->id_str = (string) $publicContact['id'];
145 $this->name = $publicContact['name'] ?: $publicContact['nick'];
146 $this->screen_name = $publicContact['nick'] ?: $publicContact['name'];
147 $this->location = $publicContact['location'] ?:
148 ContactSelector::networkToName($publicContact['network'], $publicContact['url'], $publicContact['protocol']);
150 $this->url = $publicContact['url'];
151 // No entities needed since we don't perform any shortening in the URL or description
153 'url' => ['urls' => []],
154 'description' => ['urls' => []],
156 if (!$include_user_entities) {
157 unset($this->entities);
159 $this->description = (!empty($publicContact['about']) ? BBCode::toPlaintext($publicContact['about']) : '');
160 $this->profile_image_url_https = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
161 $this->protected = false;
162 $this->followers_count = $apcontact['followers_count'] ?? 0;
163 $this->friends_count = $apcontact['following_count'] ?? 0;
164 $this->listed_count = 0;
165 $this->created_at = DateTimeFormat::utc($publicContact['created'], DateTimeFormat::API);
166 $this->favourites_count = 0;
167 $this->verified = $uid != 0;
168 $this->statuses_count = $apcontact['statuses_count'] ?? 0;
169 $this->profile_banner_url = Contact::getHeaderUrlForId($publicContact['id'], '', $publicContact['updated']);
170 $this->default_profile = false;
171 $this->default_profile_image = false;
173 if (!empty($status)) {
174 $this->status = $status;
176 unset($this->status);
179 // Unused optional fields
180 unset($this->withheld_in_countries);
181 unset($this->withheld_scope);
184 $this->profile_image_url = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
185 $this->profile_image_url_profile_size = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_THUMB);
186 $this->profile_image_url_large = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_LARGE);
187 $this->utc_offset = 0;
188 $this->time_zone = 'UTC';
189 $this->geo_enabled = false;
191 $this->contributors_enabled = false;
192 $this->is_translator = false;
193 $this->is_translation_enabled = false;
194 $this->following = in_array($userContact['rel'] ?? Contact::NOTHING, [Contact::FOLLOWER, Contact::FRIEND]);
195 $this->follow_request_sent = false;
196 $this->statusnet_blocking = false;
197 $this->notifications = false;
199 // Friendica-specific
200 $this->uid = (int)$uid;
201 $this->cid = (int)($userContact['id'] ?? 0);
202 $this->pid = (int)$publicContact['id'];
203 $this->statusnet_profile_url = $publicContact['url'];