2020-05-10 07:04:18 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2024-01-02 21:57:26 +01:00
|
|
|
* @copyright Copyright (C) 2010-2024, the Friendica project
|
2020-05-10 07:04:18 +02:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Factory\Api\Twitter;
|
|
|
|
|
|
|
|
use Friendica\BaseFactory;
|
|
|
|
use Friendica\Model\APContact;
|
|
|
|
use Friendica\Model\Contact;
|
|
|
|
use Friendica\Network\HTTPException;
|
2021-11-24 21:47:37 +01:00
|
|
|
use Friendica\Factory\Api\Twitter\Status;
|
|
|
|
use Friendica\Model\Item;
|
|
|
|
use Friendica\Model\Post;
|
|
|
|
use Psr\Log\LoggerInterface;
|
2020-05-10 07:04:18 +02:00
|
|
|
|
|
|
|
class User extends BaseFactory
|
|
|
|
{
|
2021-11-24 21:47:37 +01:00
|
|
|
/** @var Status entity */
|
|
|
|
private $status;
|
|
|
|
|
|
|
|
public function __construct(LoggerInterface $logger, Status $status)
|
|
|
|
{
|
|
|
|
parent::__construct($logger);
|
|
|
|
$this->status = $status;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-05-10 07:04:18 +02:00
|
|
|
/**
|
|
|
|
* @param int $contactId
|
|
|
|
* @param int $uid Public contact (=0) or owner user id
|
|
|
|
* @param bool $skip_status
|
|
|
|
* @param bool $include_user_entities
|
2022-08-12 13:35:27 +02:00
|
|
|
*
|
2020-05-10 07:04:18 +02:00
|
|
|
* @return \Friendica\Object\Api\Twitter\User
|
|
|
|
* @throws HTTPException\InternalServerErrorException
|
|
|
|
* @throws \ImagickException
|
|
|
|
*/
|
2022-08-12 13:35:27 +02:00
|
|
|
public function createFromContactId(int $contactId, int $uid = 0, bool $skip_status = true, bool $include_user_entities = true): \Friendica\Object\Api\Twitter\User
|
2020-05-10 07:04:18 +02:00
|
|
|
{
|
2021-07-11 11:39:34 +02:00
|
|
|
$cdata = Contact::getPublicAndUserContactID($contactId, $uid);
|
2020-05-10 07:04:18 +02:00
|
|
|
if (!empty($cdata)) {
|
2024-02-23 22:56:41 +01:00
|
|
|
$publicAccount = Contact::selectFirstAccount([], ['id' => $cdata['public']]);
|
2020-05-10 07:04:18 +02:00
|
|
|
$userContact = Contact::getById($cdata['user']);
|
|
|
|
} else {
|
2024-02-23 22:56:41 +01:00
|
|
|
$publicAccount = Contact::selectFirstAccount([], ['id' => $contactId]);
|
2020-05-10 07:04:18 +02:00
|
|
|
$userContact = [];
|
|
|
|
}
|
|
|
|
|
2024-02-23 22:56:41 +01:00
|
|
|
$apcontact = APContact::getByURL($publicAccount['url'], false);
|
2020-05-10 07:04:18 +02:00
|
|
|
|
2021-11-24 21:47:37 +01:00
|
|
|
$status = null;
|
|
|
|
|
|
|
|
if (!$skip_status) {
|
|
|
|
$post = Post::selectFirstPost(['uri-id'],
|
2024-02-23 22:56:41 +01:00
|
|
|
['author-id' => $publicAccount['id'], 'gravity' => [Item::GRAVITY_COMMENT, Item::GRAVITY_PARENT], 'private' => [Item::PUBLIC, Item::UNLISTED]],
|
2021-11-24 21:47:37 +01:00
|
|
|
['order' => ['uri-id' => true]]);
|
|
|
|
if (!empty($post['uri-id'])) {
|
|
|
|
$status = $this->status->createFromUriId($post['uri-id'], $uid)->toArray();
|
|
|
|
}
|
|
|
|
}
|
2021-11-23 11:12:11 +01:00
|
|
|
|
2024-02-23 22:56:41 +01:00
|
|
|
return new \Friendica\Object\Api\Twitter\User($publicAccount, $apcontact, $userContact, $status, $include_user_entities);
|
2020-05-10 07:04:18 +02:00
|
|
|
}
|
2021-11-17 22:28:51 +01:00
|
|
|
|
2022-08-12 13:35:27 +02:00
|
|
|
/**
|
|
|
|
* @param int $uid Public contact (=0) or owner user id
|
|
|
|
* @param bool $skip_status
|
|
|
|
* @param bool $include_user_entities
|
|
|
|
*
|
|
|
|
* @return \Friendica\Object\Api\Twitter\User
|
|
|
|
*/
|
|
|
|
public function createFromUserId(int $uid, bool $skip_status = true, bool $include_user_entities = true): \Friendica\Object\Api\Twitter\User
|
2021-11-17 22:28:51 +01:00
|
|
|
{
|
|
|
|
return $this->createFromContactId(Contact::getPublicIdByUserId($uid), $uid, $skip_status, $include_user_entities);
|
|
|
|
}
|
2020-05-10 07:04:18 +02:00
|
|
|
}
|