3 * @copyright Copyright (C) 2010-2021, 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\Proxy;
32 * @see https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/user-object
34 class User extends BaseDataTransferObject
43 protected $screen_name;
44 /** @var string|null */
48 /** @var string|null */
52 /** @var string|null */
53 protected $description;
59 protected $followers_count;
61 protected $friends_count;
63 protected $listed_count;
65 protected $favourites_count;
67 protected $statuses_count;
69 protected $created_at;
71 protected $profile_banner_url;
73 protected $profile_image_url_https;
75 protected $default_profile;
77 protected $default_profile_image;
81 protected $withheld_in_countries;
83 protected $withheld_scope;
88 * - profile_sidebar_fill_color
89 * - profile_link_color
90 * - profile_background_color
94 * @param array $publicContact Full contact table record with uid = 0
95 * @param array $apcontact Optional full apcontact table record
96 * @param array $userContact Optional full contact table record with uid != 0
97 * @param bool $skip_status Whether to remove the last status property, currently unused
98 * @param bool $include_user_entities Whether to add the entities property
99 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
101 public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $skip_status = false, $include_user_entities = true)
103 $uid = $userContact['uid'] ?? 0;
105 $this->id = (int)$publicContact['id'];
106 $this->id_str = (string) $publicContact['id'];
107 $this->name = $publicContact['name'] ?: $publicContact['nick'];
108 $this->screen_name = $publicContact['nick'] ?: $publicContact['name'];
109 $this->location = $publicContact['location'] ?:
110 ContactSelector::networkToName($publicContact['network'], $publicContact['url'], $publicContact['protocol']);
112 $this->url = $publicContact['url'];
113 // No entities needed since we don't perform any shortening in the URL or description
115 'url' => ['urls' => []],
116 'description' => ['urls' => []],
118 if (!$include_user_entities) {
119 unset($this->entities);
121 $this->description = BBCode::toPlaintext($publicContact['about']);
122 $this->profile_image_url_https = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
123 $this->protected = false;
124 $this->followers_count = $apcontact['followers_count'] ?? 0;
125 $this->friends_count = $apcontact['following_count'] ?? 0;
126 $this->listed_count = 0;
127 $this->created_at = api_date($publicContact['created']);
128 $this->favourites_count = 0;
129 $this->verified = $uid != 0;
130 $this->statuses_count = $apcontact['statuses_count'] ?? 0;
131 $this->profile_banner_url = Contact::getHeaderUrlForId($publicContact['id'], '', $publicContact['updated']);
132 $this->default_profile = false;
133 $this->default_profile_image = false;
135 // @TODO Replace skip_status parameter with an optional Status parameter
136 unset($this->status);
138 // Unused optional fields
139 unset($this->withheld_in_countries);
140 unset($this->withheld_scope);
143 $this->profile_image_url = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_MICRO);
144 $this->profile_image_url_profile_size = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_THUMB);
145 $this->profile_image_url_large = Contact::getAvatarUrlForUrl($publicContact['url'], $uid, Proxy::SIZE_LARGE);
146 $this->utc_offset = 0;
147 $this->time_zone = 'UTC';
148 $this->geo_enabled = false;
150 $this->contributors_enabled = false;
151 $this->is_translator = false;
152 $this->is_translation_enabled = false;
153 $this->following = in_array($userContact['rel'] ?? Contact::NOTHING, [Contact::FOLLOWER, Contact::FRIEND]);
154 $this->follow_request_sent = false;
155 $this->statusnet_blocking = false;
156 $this->notifications = false;
158 // Friendica-specific
159 $this->uid = (int)$uid;
160 $this->cid = (int)($userContact['id'] ?? 0);
161 $this->pid = (int)$publicContact['id'];
162 $this->self = (boolean)($userContact['self'] ?? false);
163 $this->network = $publicContact['network'] ?: Protocol::DFRN;
164 $this->statusnet_profile_url = $publicContact['url'];