use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
use Friendica\Util\Network;
-use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
use Friendica\Util\XML;
{
$body = api_add_attachments_to_body($item);
- $entities = api_get_entitities($statustext, $body);
+ $entities = api_get_entitities($statustext, $body, $item['uri-id']);
// Add pictures to the attachment array and remove them from the body
- $attachments = api_get_attachments($body);
+ $attachments = api_get_attachments($body, $item['uri-id']);
// Workaround for ostatus messages where the title is identically to the body
$html = BBCode::convert(api_clean_plain_items($body), false, BBCode::API, true);
* @return array
* @throws InternalServerErrorException
*/
-function api_get_attachments(&$body)
+function api_get_attachments(&$body, $uriid)
{
$body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
$body = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $body);
$imagedata = Images::getInfoFromURLCached($image);
if ($imagedata) {
- if (DI::config()->get("system", "proxy_disabled")) {
- $attachments[] = ["url" => $image, "mimetype" => $imagedata["mime"], "size" => $imagedata["size"]];
- } else {
- $attachments[] = ["url" => ProxyUtils::proxifyUrl($image), "mimetype" => $imagedata["mime"], "size" => $imagedata["size"]];
- }
+ $attachments[] = ["url" => Post\Link::getByLink($uriid, $image), "mimetype" => $imagedata["mime"], "size" => $imagedata["size"]];
}
}
* @throws InternalServerErrorException
* @todo Links at the first character of the post
*/
-function api_get_entitities(&$text, $bbcode)
+function api_get_entitities(&$text, $bbcode, $uriid)
{
$include_entities = strtolower($_REQUEST['include_entities'] ?? 'false');
preg_match_all("/\[img](.*?)\[\/img\]/ism", $bbcode, $images);
foreach ($images[1] as $image) {
- $replace = ProxyUtils::proxifyUrl($image);
+ $replace = Post\Link::getByLink($uriid, $image);
$text = str_replace($image, $replace, $text);
}
return [];
if (!($start === false)) {
$image = Images::getInfoFromURLCached($url);
if ($image) {
- // If image cache is activated, then use the following sizes:
- // thumb (150), small (340), medium (600) and large (1024)
- if (!DI::config()->get("system", "proxy_disabled")) {
- $media_url = ProxyUtils::proxifyUrl($url);
-
- $sizes = [];
- $scale = Images::getScalingDimensions($image[0], $image[1], 150);
- $sizes["thumb"] = ["w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"];
-
- if (($image[0] > 150) || ($image[1] > 150)) {
- $scale = Images::getScalingDimensions($image[0], $image[1], 340);
- $sizes["small"] = ["w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"];
- }
-
- $scale = Images::getScalingDimensions($image[0], $image[1], 600);
- $sizes["medium"] = ["w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"];
-
- if (($image[0] > 600) || ($image[1] > 600)) {
- $scale = Images::getScalingDimensions($image[0], $image[1], 1024);
- $sizes["large"] = ["w" => $scale["width"], "h" => $scale["height"], "resize" => "fit"];
- }
- } else {
- $media_url = $url;
- $sizes["medium"] = ["w" => $image[0], "h" => $image[1], "resize" => "fit"];
- }
+ $media_url = Post\Link::getByLink($uriid, $url);
+ $sizes["medium"] = ["w" => $image[0], "h" => $image[1], "resize" => "fit"];
$entities["media"][] = [
"id" => $start+1,
public function testApiGetAttachments()
{
$body = 'body';
- self::assertEmpty(api_get_attachments($body));
+ self::assertEmpty(api_get_attachments($body, 0));
}
/**
public function testApiGetAttachmentsWithImage()
{
$body = '[img]http://via.placeholder.com/1x1.png[/img]';
- self::assertIsArray(api_get_attachments($body));
+ self::assertIsArray(api_get_attachments($body, 0));
}
/**
{
$_SERVER['HTTP_USER_AGENT'] = 'AndStatus';
$body = '[img]http://via.placeholder.com/1x1.png[/img]';
- self::assertIsArray(api_get_attachments($body));
+ self::assertIsArray(api_get_attachments($body, 0));
}
/**
public function testApiGetEntitities()
{
$text = 'text';
- self::assertIsArray(api_get_entitities($text, 'bbcode'));
+ self::assertIsArray(api_get_entitities($text, 'bbcode', 0));
}
/**
{
$_REQUEST['include_entities'] = 'true';
$text = 'text';
- $result = api_get_entitities($text, 'bbcode');
+ $result = api_get_entitities($text, 'bbcode', 0);
self::assertIsArray($result['hashtags']);
self::assertIsArray($result['symbols']);
self::assertIsArray($result['urls']);