]> git.mxchange.org Git - friendica.git/blob - src/Object/Api/Twitter/User.php
Changed:
[friendica.git] / src / Object / Api / Twitter / User.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Object\Api\Twitter;
23
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;
31
32 /**
33  * @see https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/user-object
34  */
35 class User extends BaseDataTransferObject
36 {
37         /** @var int */
38         protected $id;
39         /** @var string */
40         protected $id_str;
41         /** @var string */
42         protected $name;
43         /** @var string */
44         protected $screen_name;
45         /** @var string|null */
46         protected $location;
47         /** @var array */
48         protected $derived;
49         /** @var string|null */
50         protected $url;
51         /** @var array */
52         protected $entities;
53         /** @var string|null */
54         protected $description;
55         /** @var bool */
56         protected $protected;
57         /** @var bool */
58         protected $verified;
59         /** @var int */
60         protected $followers_count;
61         /** @var int */
62         protected $friends_count;
63         /** @var int */
64         protected $listed_count;
65         /** @var int */
66         protected $favourites_count;
67         /** @var int */
68         protected $statuses_count;
69         /** @var string */
70         protected $created_at;
71         /** @var string */
72         protected $profile_banner_url;
73         /** @var string */
74         protected $profile_image_url_https;
75         /** @var bool */
76         protected $default_profile;
77         /** @var bool */
78         protected $default_profile_image;
79         /** @var Status */
80         protected $status;
81         /** @var array */
82         protected $withheld_in_countries;
83         /** @var string */
84         protected $withheld_scope;
85
86         /**
87          * Missing fields:
88          *
89          * - profile_sidebar_fill_color
90          * - profile_link_color
91          * - profile_background_color
92          */
93
94         /**
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
101          */
102         public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $status = null, $include_user_entities = true)
103         {
104                 $uid = $userContact['uid'] ?? 0;
105
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']);
112                 $this->derived                 = [];
113                 $this->url                     = $publicContact['url'];
114                 // No entities needed since we don't perform any shortening in the URL or description
115                 $this->entities            = [
116                         'url' => ['urls' => []],
117                         'description' => ['urls' => []],
118                 ];
119                 if (!$include_user_entities) {
120                         unset($this->entities);
121                 }
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;
135
136                 if (!empty($status)) {
137                         $this->status = $status;
138                 } else {
139                         unset($this->status);
140                 }
141
142                 //  Unused optional fields
143                 unset($this->withheld_in_countries);
144                 unset($this->withheld_scope);
145
146                 // Deprecated
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;
153                 $this->lang                           = null;
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;
161
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'];
167         }
168 }