<?php
/**
- * @copyright Copyright (C) 2010-2021, the Friendica project
+ * @copyright Copyright (C) 2010-2022, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
use Friendica\Model\Item;
use Friendica\Model\Photo;
use Friendica\Model\Post;
-use Friendica\Network\HTTPClientOptions;
+use Friendica\Network\HTTPClient\Client\HttpClientAccept;
+use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Util\Images;
use Friendica\Util\Network;
use Friendica\Util\ParseUrl;
// Fetch the mimetype or size if missing.
if (empty($media['mimetype']) || empty($media['size'])) {
$timeout = DI::config()->get('system', 'xrd_timeout');
- $curlResult = DI::httpClient()->head($media['url'], [HTTPClientOptions::TIMEOUT => $timeout]);
+ $curlResult = DI::httpClient()->head($media['url'], [HttpClientOptions::TIMEOUT => $timeout]);
+
+ // Workaround for systems that can't handle a HEAD request
+ if (!$curlResult->isSuccess() && ($curlResult->getReturnCode() == 405)) {
+ $curlResult = DI::httpClient()->get($media['url'], HttpClientAccept::DEFAULT, [HttpClientOptions::TIMEOUT => $timeout]);
+ }
+
if ($curlResult->isSuccess()) {
if (empty($media['mimetype'])) {
$media['mimetype'] = $curlResult->getHeader('Content-Type')[0] ?? '';
$condition = DBA::mergeConditions($condition, ['type' => $types]);
}
- return DBA::selectToArray('post-media', [], $condition);
+ return DBA::selectToArray('post-media', [], $condition, ['order' => ['id']]);
}
/**
* @param int $uri_id
* @param string $guid
* @param array $links list of links that shouldn't be added
+ * @param bool $has_media
* @return array attachments
*/
- public static function splitAttachments(int $uri_id, string $guid = '', array $links = [])
+ public static function splitAttachments(int $uri_id, string $guid = '', array $links = [], bool $has_media = true)
{
$attachments = ['visual' => [], 'link' => [], 'additional' => []];
+ if (!$has_media) {
+ return $attachments;
+ }
+
$media = self::getByURIId($uri_id);
if (empty($media)) {
return $attachments;