Simplify image url

This commit is contained in:
Michael 2023-05-17 20:30:45 +00:00
parent 7c266be206
commit 1010443031
4 changed files with 6 additions and 15 deletions

View file

@ -24,7 +24,6 @@ namespace Friendica\Content\Text;
use DOMDocument;
use DOMXPath;
use Friendica\Protocol\HTTP\MediaType;
use Friendica\Content\Widget\ContactBlock;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\Core\Search;

View file

@ -1004,7 +1004,7 @@ class Media
}
if ($media['type'] == self::IMAGE) {
$body .= "\n" . Images::getBBCodeByUrl($media['url'], $media['preview'], $media['description']);
$body .= "\n" . Images::getBBCodeByUrl($media['url'], $media['preview'], $media['description'] ?? '');
} elseif ($media['type'] == self::AUDIO) {
$body .= "\n[audio]" . $media['url'] . "[/audio]\n";
} elseif ($media['type'] == self::VIDEO) {

View file

@ -179,7 +179,7 @@ class Upload extends \Friendica\BaseModule
}
$this->logger->info('upload done');
$this->return(200, "\n\n" . Images::getBBCodeByResource($resource_id, $owner['nickname'], $preview, $image->getExt(), '') . "\n\n");
$this->return(200, "\n\n" . Images::getBBCodeByResource($resource_id, $owner['nickname'], $preview, $image->getExt()) . "\n\n");
}
/**

View file

@ -327,7 +327,7 @@ class Images
* @param string $description
* @return string
*/
public static function getBBCodeByResource(string $resource_id, string $nickname, int $preview, string $ext, string $description = null): string
public static function getBBCodeByResource(string $resource_id, string $nickname, int $preview, string $ext, string $description = ''): string
{
return self::getBBCodeByUrl(
DI::baseUrl() . '/photos/' . $nickname . '/image/' . $resource_id,
@ -344,20 +344,12 @@ class Images
* @param string $description
* @return string
*/
public static function getBBCodeByUrl(string $photo, string $preview = null, string $description = null): string
public static function getBBCodeByUrl(string $photo, string $preview = null, string $description = ''): string
{
if (!empty($preview)) {
if (!is_null($description)) {
return '[url=' . $photo . '][img=' . $preview . ']' . $description . '[/img][/url]';
} else {
return '[url=' . $photo . '][img]' . $preview . '[/img][/url]';
}
return '[url=' . $photo . '][img=' . $preview . ']' . $description . '[/img][/url]';
}
if (!is_null($description)) {
return '[img=' . $photo . ']' . $description . '[/img]';
} else {
return '[img]' . $photo . '[/img]';
}
return '[img=' . $photo . ']' . $description . '[/img]';
}
}