More objects added

This commit is contained in:
Michael 2021-11-23 10:12:11 +00:00
parent 8211cef49d
commit b56ccbcf2b
14 changed files with 722 additions and 29 deletions

View file

@ -0,0 +1,65 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @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\Object\Api\Twitter;
use Friendica\BaseDataTransferObject;
/**
* Class Hashtag
*
* @see https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/entities#hashtags
*/
class Hashtag extends BaseDataTransferObject
{
/** @var array */
protected $indices;
/** @var string */
protected $text;
/**
* Creates a hashtag
*
* @param array $attachment
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function __construct(string $name, array $indices)
{
$this->indices = $indices;
$this->text = $name;
}
/**
* Returns the current entity as an array
*
* @return array
*/
public function toArray(): array
{
$status = parent::toArray();
if (empty($status['indices'])) {
unset($status['indices']);
}
return $status;
}
}

View file

@ -0,0 +1,108 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @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\Object\Api\Twitter;
use Friendica\BaseDataTransferObject;
use Friendica\Model\Post;
/**
* Class Media
*
* @see https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/entities#media
*/
class Media extends BaseDataTransferObject
{
/** @var string */
protected $display_url;
/** @var string */
protected $expanded_url;
/** @var int */
protected $id;
/** @var string */
protected $id_str;
/** @var array */
protected $indices;
/** @var string */
protected $media_url;
/** @var string */
protected $media_url_https;
/** @var string */
protected $sizes;
/** @var string */
protected $type;
/** @var string */
protected $url;
/**
* Creates a media entity array
*
* @param array $attachment
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function __construct(array $media, string $url, array $indices)
{
$this->display_url = $media['url'];
$this->expanded_url = $media['url'];
$this->id = $media['id'];
$this->id_str = (string)$media['id'];
$this->indices = $indices;
$this->media_url = $media['url'];
$this->media_url_https = $media['url'];
$this->type = $media['type'] == Post\Media::IMAGE ? 'photo' : 'video';
$this->url = $url;
if (!empty($media['height']) && !empty($media['width'])) {
if (($media['height'] <= 680) && ($media['width'] <= 680)) {
$size = 'small';
} elseif (($media['height'] <= 1200) && ($media['width'] <= 1200)) {
$size = 'medium';
} else {
$size = 'large';
}
$this->sizes = [
$size => [
'h' => $media['height'],
'resize' => 'fit',
'w' => $media['width'],
]
];
}
}
/**
* Returns the current entity as an array
*
* @return array
*/
public function toArray(): array
{
$status = parent::toArray();
if (empty($status['indices'])) {
unset($status['indices']);
}
return $status;
}
}

View file

@ -0,0 +1,77 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @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\Object\Api\Twitter;
use Friendica\App\BaseURL;
use Friendica\BaseDataTransferObject;
/**
* Class Mention
*
* @see https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/entities#mentions
*/
class Mention extends BaseDataTransferObject
{
/** @var int */
protected $id;
/** @var string */
protected $id_str;
/** @var array */
protected $indices;
/** @var string */
protected $name;
/** @var string */
protected $screen_name;
/**
* Creates a mention record from an tag-view record.
*
* @param BaseURL $baseUrl
* @param array $tag tag-view record
* @param array $contact contact table record
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function __construct(array $tag, array $contact, array $indices)
{
$this->id = (string)($contact['id'] ?? 0);
$this->id_str = (string)($contact['id'] ?? 0);
$this->indices = $indices;
$this->name = $tag['name'];
$this->screen_name = $contact['nick'];
}
/**
* Returns the current entity as an array
*
* @return array
*/
public function toArray(): array
{
$status = parent::toArray();
if (empty($status['indices'])) {
unset($status['indices']);
}
return $status;
}
}

View file

@ -24,14 +24,13 @@ namespace Friendica\Object\Api\Twitter;
use Friendica\BaseDataTransferObject;
use Friendica\Content\ContactSelector;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Model\Item;
use Friendica\Util\DateTimeFormat;
/**
* Class Status
*
* @see https://docs.joinmastodon.org/entities/status
* @see https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/tweet
*/
class Status extends BaseDataTransferObject
{
@ -83,11 +82,13 @@ class Status extends BaseDataTransferObject
protected $statusnet_conversation_id;
/** @var bool */
protected $friendica_private;
/** @var Attachment */
protected $attachments = [];
protected $geo;
/** @var array */
protected $friendica_activities;
/** @var array */
protected $entities;
/** @var array */
protected $extended_entities;
/**
* Creates a status record from an item record.
@ -95,7 +96,7 @@ class Status extends BaseDataTransferObject
* @param array $item
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function __construct(array $item, User $author, User $owner, array $retweeted, array $quoted, array $attachments, array $geo, array $friendica_activities, array $entities, int $friendica_comments)
public function __construct(string $text, array $item, User $author, User $owner, array $retweeted, array $quoted, array $geo, array $friendica_activities, array $entities, int $friendica_comments)
{
$this->id = (int)$item['id'];
$this->id_str = (string)$item['id'];
@ -111,7 +112,7 @@ class Status extends BaseDataTransferObject
$this->in_reply_to_screen_name = $item['parent-author-nick'];
}
$this->text = trim(HTML::toPlaintext(BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::API), 0));
$this->text = $text;
$this->friendica_title = $item['title'];
$this->statusnet_html = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::API);
$this->friendica_html = BBCode::convertForUriId($item['uri-id'], $item['body'], BBCode::EXTERNAL);
@ -126,10 +127,10 @@ class Status extends BaseDataTransferObject
$this->favorited = (bool)$item['starred'];
$this->friendica_comments = $friendica_comments;
$this->source = $item['app'] ?: 'web';
$this->attachments = $attachments;
$this->geo = $geo;
$this->friendica_activities = $friendica_activities;
$this->entities = $entities;
$this->extended_entities = $entities;
if ($this->source == 'web') {
$this->source = ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']);

View file

@ -0,0 +1,71 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @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\Object\Api\Twitter;
use Friendica\BaseDataTransferObject;
/**
* Class Url
*
* @see https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/entities#urls
*/
class Url extends BaseDataTransferObject
{
/** @var string */
protected $display_url;
/** @var string */
protected $expanded_url;
/** @var array */
protected $indices;
/** @var string */
protected $url;
/**
* Creates an URL entity array
*
* @param array $attachment
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function __construct(array $media, array $indices)
{
$this->display_url = $media['url'];
$this->expanded_url = $media['url'];
$this->indices = $indices;
$this->url = $media['url'];
}
/**
* Returns the current entity as an array
*
* @return array
*/
public function toArray(): array
{
$status = parent::toArray();
if (empty($status['indices'])) {
unset($status['indices']);
}
return $status;
}
}

View file

@ -99,7 +99,7 @@ class User extends BaseDataTransferObject
* @param bool $include_user_entities Whether to add the entities property
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $skip_status = false, $include_user_entities = true)
public function __construct(array $publicContact, array $apcontact = [], array $userContact = [], $status = null, $include_user_entities = true)
{
$uid = $userContact['uid'] ?? 0;
@ -133,8 +133,11 @@ class User extends BaseDataTransferObject
$this->default_profile = false;
$this->default_profile_image = false;
// @TODO Replace skip_status parameter with an optional Status parameter
unset($this->status);
if (!empty($status)) {
$this->status = $status;
} else {
unset($this->status);
}
// Unused optional fields
unset($this->withheld_in_countries);