mirror of
https://github.com/friendica/friendica
synced 2025-04-26 00:30:12 +00:00
Improved cards handling, simplified Bearer handling
This commit is contained in:
parent
7d8c152aaf
commit
bade0a2345
7 changed files with 120 additions and 29 deletions
78
src/Factory/Api/Mastodon/Card.php
Normal file
78
src/Factory/Api/Mastodon/Card.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?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\Factory\Api\Mastodon;
|
||||
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Network\HTTPException;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
class Card extends BaseFactory
|
||||
{
|
||||
/**
|
||||
* @param int $uriId Uri-ID of the item
|
||||
* @return \Friendica\Object\Api\Mastodon\Card
|
||||
* @throws HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public function createFromUriId(int $uriId)
|
||||
{
|
||||
$item = Post::selectFirst(['nody'], ['uri-id' => $uriId]);
|
||||
if (!empty($item['body'])) {
|
||||
$data = BBCode::getAttachmentData($item['body']);
|
||||
}
|
||||
|
||||
foreach (Post\Media::getByURIId($uriId, [Post\Media::HTML]) as $attached) {
|
||||
if ((empty($data['url']) || Strings::compareLink($data['url'], $attached['url'])) &&
|
||||
(!empty($attached['description']) || !empty($attached['image']) || !empty($attached['preview']))) {
|
||||
$parts = parse_url($attached['url']);
|
||||
if (!empty($parts['scheme']) && !empty($parts['host'])) {
|
||||
if (empty($attached['publisher-name'])) {
|
||||
$attached['publisher-name'] = $parts['host'];
|
||||
}
|
||||
if (empty($attached['publisher-url']) || empty(parse_url($attached['publisher-url'], PHP_URL_SCHEME))) {
|
||||
$attached['publisher-url'] = $parts['scheme'] . '://' . $parts['host'];
|
||||
|
||||
if (!empty($parts['port'])) {
|
||||
$attached['publisher-url'] .= ':' . $parts['port'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['url'] = $attached['url'];
|
||||
$data['title'] = $attached['name'];
|
||||
$data['description'] = $attached['description'];
|
||||
$data['type'] = 'link';
|
||||
$data['author_name'] = $attached['author-name'];
|
||||
$data['author_url'] = $attached['author-url'];
|
||||
$data['provider_name'] = $attached['publisher-name'];
|
||||
$data['provider_url'] = $attached['publisher-url'];
|
||||
$data['image'] = $attached['preview'];
|
||||
$data['width'] = $attached['preview-width'];
|
||||
$data['height'] = $attached['preview-height'];
|
||||
}
|
||||
}
|
||||
|
||||
return new \Friendica\Object\Api\Mastodon\Card($data);
|
||||
}
|
||||
}
|
|
@ -24,7 +24,6 @@ namespace Friendica\Factory\Api\Mastodon;
|
|||
use Friendica\App\BaseURL;
|
||||
use Friendica\BaseFactory;
|
||||
use Friendica\Content\ContactSelector;
|
||||
use Friendica\Content\Text\BBCode;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Post;
|
||||
|
@ -86,12 +85,10 @@ class Status extends BaseFactory
|
|||
|
||||
$sensitive = DBA::exists('tag-view', ['uri-id' => $uriId, 'name' => 'nsfw']);
|
||||
$application = new \Friendica\Object\Api\Mastodon\Application($item['app'] ?: ContactSelector::networkToName($item['network'], $item['author-link']));
|
||||
$mentions = DI::mstdnMention()->createFromUriId($uriId);
|
||||
$tags = DI::mstdnTag()->createFromUriId($uriId);
|
||||
|
||||
$data = BBCode::getAttachmentData($item['body']);
|
||||
$card = new \Friendica\Object\Api\Mastodon\Card($data);
|
||||
|
||||
$mentions = DI::mstdnMention()->createFromUriId($uriId);
|
||||
$tags = DI::mstdnTag()->createFromUriId($uriId);
|
||||
$card = DI::mstdnCard()->createFromUriId($uriId);
|
||||
$attachments = DI::mstdnAttachment()->createFromUriId($uriId);
|
||||
|
||||
if ($item['vid'] == Verb::getID(Activity::ANNOUNCE)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue