3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Object\Api\Twitter;
24 use Friendica\BaseDataTransferObject;
25 use Friendica\Model\Post;
30 * @see https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/entities#media
32 class Media extends BaseDataTransferObject
35 protected $display_url;
37 protected $expanded_url;
47 protected $media_url_https;
56 * Creates a media entity array
58 * @param array $attachment
59 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
61 public function __construct(array $media, string $url, array $indices)
63 $this->display_url = $media['url'];
64 $this->expanded_url = $media['url'];
65 $this->id = $media['id'];
66 $this->id_str = (string)$media['id'];
67 $this->indices = $indices;
68 $this->media_url = $media['url'];
69 $this->media_url_https = $media['url'];
70 $this->type = $media['type'] == Post\Media::IMAGE ? 'photo' : 'video';
73 if (!empty($media['height']) && !empty($media['width'])) {
74 if (($media['height'] <= 680) && ($media['width'] <= 680)) {
76 } elseif (($media['height'] <= 1200) && ($media['width'] <= 1200)) {
84 'h' => $media['height'],
86 'w' => $media['width'],
93 * Returns the current entity as an array
97 public function toArray(): array
99 $status = parent::toArray();
101 if (empty($status['indices'])) {
102 unset($status['indices']);