3 * @copyright Copyright (C) 2020, Friendica
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;
29 * @see https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/user-object
31 class User extends BaseDataTransferObject
40 protected $screen_name;
41 /** @var string|null */
45 /** @var string|null */
49 /** @var string|null */
50 protected $description;
56 protected $followers_count;
58 protected $friends_count;
60 protected $listed_count;
62 protected $favourites_count;
64 protected $statuses_count;
66 protected $created_at;
68 protected $profile_banner_url;
70 protected $profile_image_url_https;
72 protected $default_profile;
74 protected $default_profile_image;
78 protected $withheld_in_countries;
80 protected $withheld_scope;
83 * @param array $publicContact Full contact table record with uid = 0
84 * @param array $apcontact Optional full apcontact table record
85 * @param array $userContact Optional full contact table record with uid != 0
86 * @param bool $skip_status Whether to remove the last status property, currently unused
87 * @param bool $include_user_entities Whether to add the entities property
88 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
90 public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $skip_status = false, $include_user_entities = true)
92 $this->id = (int)$publicContact['id'];
93 $this->id_str = (string) $publicContact['id'];
94 $this->name = $publicContact['name'];
95 $this->screen_name = $publicContact['nick'] ?: $publicContact['name'];
96 $this->location = $publicContact['location'] ?:
97 ContactSelector::networkToName($publicContact['network'], $publicContact['url'], $publicContact['protocol']);
99 $this->url = $publicContact['url'];
100 // No entities needed since we don't perform any shortening in the URL or description
102 'url' => ['urls' => []],
103 'description' => ['urls' => []],
105 if (!$include_user_entities) {
106 unset($this->entities);
108 $this->description = BBCode::toPlaintext($publicContact['about']);
109 $this->profile_image_url_https = $userContact['avatar'] ?? $publicContact['avatar'];
110 $this->protected = false;
111 $this->followers_count = $apcontact['followers_count'] ?? 0;
112 $this->friends_count = $apcontact['following_count'] ?? 0;
113 $this->listed_count = 0;
114 $this->created_at = api_date($publicContact['created']);
115 $this->favourites_count = 0;
116 $this->verified = false;
117 $this->statuses_count = $apcontact['statuses_count'] ?? 0;
118 $this->profile_banner_url = '';
119 $this->default_profile = false;
120 $this->default_profile_image = false;
122 // @TODO Replace skip_status parameter with an optional Status parameter
123 unset($this->status);
125 // Unused optional fields
126 unset($this->withheld_in_countries);
127 unset($this->withheld_scope);
130 $this->profile_image_url = $userContact['avatar'] ?? $publicContact['avatar'];
131 $this->profile_image_url_profile_size = $publicContact['thumb'];
132 $this->profile_image_url_large = $publicContact['photo'];
133 $this->utc_offset = 0;
134 $this->time_zone = 'UTC';
135 $this->geo_enabled = false;
137 $this->contributors_enabled = false;
138 $this->is_translator = false;
139 $this->is_translation_enabled = false;
140 $this->following = false;
141 $this->follow_request_sent = false;
142 $this->statusnet_blocking = false;
143 $this->notifications = false;
145 // Friendica-specific
146 $this->uid = (int)$userContact['uid'] ?? 0;
147 $this->cid = (int)$userContact['id'] ?? 0;
148 $this->pid = (int)$publicContact['id'];
149 $this->self = (boolean)$userContact['self'] ?? false;
150 $this->network = $publicContact['network'];
151 $this->statusnet_profile_url = $publicContact['url'];