]> git.mxchange.org Git - friendica.git/blob - src/Factory/Api/Twitter/User.php
e545bd78cbdf40a9cb6d37496550348a89674371
[friendica.git] / src / Factory / Api / Twitter / User.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, 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\Factory\Api\Twitter;
23
24 use Friendica\BaseFactory;
25 use Friendica\Model\APContact;
26 use Friendica\Model\Contact;
27 use Friendica\Network\HTTPException;
28
29 class User extends BaseFactory
30 {
31         /**
32          * @param int  $contactId
33          * @param int  $uid Public contact (=0) or owner user id
34          * @param bool $skip_status
35          * @param bool $include_user_entities
36          * @return \Friendica\Object\Api\Twitter\User
37          * @throws HTTPException\InternalServerErrorException
38          * @throws \ImagickException
39          */
40         public function createFromContactId(int $contactId, $uid = 0, $skip_status = false, $include_user_entities = true)
41         {
42                 $cdata = Contact::getPublicAndUserContactID($contactId, $uid);
43                 if (!empty($cdata)) {
44                         $publicContact = Contact::getById($cdata['public']);
45                         $userContact = Contact::getById($cdata['user']);
46                 } else {
47                         $publicContact = Contact::getById($contactId);
48                         $userContact = [];
49                 }
50
51                 $apcontact = APContact::getByURL($publicContact['url'], false);
52
53                 return new \Friendica\Object\Api\Twitter\User($publicContact, $apcontact, $userContact, $skip_status, $include_user_entities);
54         }
55
56         public function createFromUserId(int $uid, $skip_status = false, $include_user_entities = true)
57         {
58                 return $this->createFromContactId(Contact::getPublicIdByUserId($uid), $uid, $skip_status, $include_user_entities);
59         }
60 }