From 29c8bd85157607f58f2df409cb4dd1f32310ee38 Mon Sep 17 00:00:00 2001 From: Hank Grabowski Date: Tue, 28 Feb 2023 15:35:37 -0500 Subject: [PATCH 1/7] Add title/spoiler text handling and capturing invalid update to Mastodon edit --- src/Module/Api/Mastodon/Statuses.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Module/Api/Mastodon/Statuses.php b/src/Module/Api/Mastodon/Statuses.php index 01856b2d8b..bf5c9aa6a2 100644 --- a/src/Module/Api/Mastodon/Statuses.php +++ b/src/Module/Api/Mastodon/Statuses.php @@ -21,6 +21,7 @@ namespace Friendica\Module\Api\Mastodon; +use Friendica\Content\Text\BBCode; use Friendica\Content\Text\Markdown; use Friendica\Core\Protocol; use Friendica\Core\System; @@ -50,9 +51,9 @@ class Statuses extends BaseApi $request = $this->getRequest([ 'status' => '', // Text content of the status. If media_ids is provided, this becomes optional. Attaching a poll is optional while status is provided. - 'in_reply_to_id' => 0, // ID of the status being replied to, if status is a reply 'spoiler_text' => '', // Text to be shown as a warning or subject before the actual content. Statuses are generally collapsed behind this field. 'language' => '', // ISO 639 language code for this status. + 'friendica' => [], ], $request); $owner = User::getOwnerDataById($uid); @@ -65,7 +66,7 @@ class Statuses extends BaseApi 'origin' => true, ]; - $post = Post::selectFirst(['uri-id', 'id'], $condition); + $post = Post::selectFirst(['uri-id', 'id', 'gravity'], $condition); if (empty($post['id'])) { throw new HTTPException\NotFoundException('Item with URI ID ' . $this->parameters['id'] . ' not found for user ' . $uid . '.'); } @@ -77,14 +78,25 @@ class Statuses extends BaseApi $item['language'] = json_encode([$request['language'] => 1]); } - if (!empty($request['spoiler_text'])) { - if (($request['in_reply_to_id'] == $post['uri-id']) && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { - $item['title'] = $request['spoiler_text']; + if ($post['gravity'] == 0) { + $item['title'] = $request['friendica']['title'] ?? ''; + } + + $spoiler_text = $request['spoiler_text']; + + if (!empty($spoiler_text)) { + if (!isset($request['friendica']['title']) && $post['gravity'] == 0 && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { + $item['title'] = $spoiler_text; } else { - $item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $request['spoiler_text'] . "[/abstract]\n" . $item['body']; + $item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $spoiler_text . "[/abstract]\n" . $item['body']; + $item['content-warning'] = BBCode::toPlaintext($spoiler_text); } } + if (!Item::isValid($item)) { + throw new \Exception('Missing parameters in definitien'); + } + Item::update($item, ['id' => $post['id']]); Item::updateDisplayCache($post['uri-id']); From 804152870ff9c11c7bed644fa1bf93593510410f Mon Sep 17 00:00:00 2001 From: Hank G Date: Sun, 12 Mar 2023 11:43:59 -0400 Subject: [PATCH 2/7] Apply suggestions from code review Co-authored-by: Hypolite Petovan --- src/Module/Api/Mastodon/Statuses.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Module/Api/Mastodon/Statuses.php b/src/Module/Api/Mastodon/Statuses.php index bf5c9aa6a2..64fba420dd 100644 --- a/src/Module/Api/Mastodon/Statuses.php +++ b/src/Module/Api/Mastodon/Statuses.php @@ -78,14 +78,14 @@ class Statuses extends BaseApi $item['language'] = json_encode([$request['language'] => 1]); } - if ($post['gravity'] == 0) { + if ($post['gravity'] == Item::GRAVITY_PARENT) { $item['title'] = $request['friendica']['title'] ?? ''; } $spoiler_text = $request['spoiler_text']; if (!empty($spoiler_text)) { - if (!isset($request['friendica']['title']) && $post['gravity'] == 0 && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { + if (!isset($request['friendica']['title']) && $post['gravity'] == Item::GRAVITY_PARENT && DI::pConfig()->get($uid, 'system', 'api_spoiler_title', true)) { $item['title'] = $spoiler_text; } else { $item['body'] = '[abstract=' . Protocol::ACTIVITYPUB . ']' . $spoiler_text . "[/abstract]\n" . $item['body']; From 028b609b547d186c8c311d86f101230e45a707b4 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 12 Mar 2023 17:55:57 -0400 Subject: [PATCH 3/7] Cast the base URL as string in /friendica/json - This was causing the data.url key to have no value, which broke the directory integration --- src/Module/Friendica.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Friendica.php b/src/Module/Friendica.php index 2c669e886c..90869878e4 100644 --- a/src/Module/Friendica.php +++ b/src/Module/Friendica.php @@ -172,7 +172,7 @@ class Friendica extends BaseModule $data = [ 'version' => App::VERSION, - 'url' => DI::baseUrl(), + 'url' => (string)DI::baseUrl(), 'addons' => $visible_addons, 'locked_features' => $locked_features, 'explicit_content' => intval($config->get('system', 'explicit_content', 0)), From 403411b1df223ea6c1ea0b481266e03cf476aba1 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 12 Mar 2023 03:02:46 -0400 Subject: [PATCH 4/7] [Database 1517] Increase the size of the process.hostname field --- database.sql | 4 ++-- doc/database/db_process.md | 2 +- static/dbstructure.config.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/database.sql b/database.sql index ac3eaaf1df..e05a420fa8 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2023.03-dev (Giant Rhubarb) --- DB_UPDATE_VERSION 1516 +-- DB_UPDATE_VERSION 1517 -- ------------------------------------------ @@ -1570,7 +1570,7 @@ CREATE TABLE IF NOT EXISTS `post-user-notification` ( -- CREATE TABLE IF NOT EXISTS `process` ( `pid` int unsigned NOT NULL COMMENT 'The ID of the process', - `hostname` varchar(32) NOT NULL COMMENT 'The name of the host the process is ran on', + `hostname` varchar(255) NOT NULL COMMENT 'The name of the host the process is ran on', `command` varbinary(32) NOT NULL DEFAULT '' COMMENT '', `created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '', PRIMARY KEY(`pid`,`hostname`), diff --git a/doc/database/db_process.md b/doc/database/db_process.md index c0eb75f297..b1a52e01b7 100644 --- a/doc/database/db_process.md +++ b/doc/database/db_process.md @@ -9,7 +9,7 @@ Fields | Field | Description | Type | Null | Key | Default | Extra | | -------- | ------------------------------------------ | ------------- | ---- | --- | ------------------- | ----- | | pid | The ID of the process | int unsigned | NO | PRI | NULL | | -| hostname | The name of the host the process is ran on | varchar(32) | NO | PRI | NULL | | +| hostname | The name of the host the process is ran on | varchar(255) | NO | PRI | NULL | | | command | | varbinary(32) | NO | | | | | created | | datetime | NO | | 0001-01-01 00:00:00 | | diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index cc420a449b..6eaad609ef 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -55,7 +55,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1516); + define('DB_UPDATE_VERSION', 1517); } return [ @@ -1565,7 +1565,7 @@ return [ "comment" => "Currently running system processes", "fields" => [ "pid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "comment" => "The ID of the process"], - "hostname" => ["type" => "varchar(32)", "not null" => "1", "primary" => "1", "comment" => "The name of the host the process is ran on"], + "hostname" => ["type" => "varchar(255)", "not null" => "1", "primary" => "1", "comment" => "The name of the host the process is ran on"], "command" => ["type" => "varbinary(32)", "not null" => "1", "default" => "", "comment" => ""], "created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""], ], From 3b8b562d20addc180ff8144ce034c9b1a7863f6a Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Mar 2023 05:04:55 +0000 Subject: [PATCH 5/7] The function "getAttachedData" is replaced by a simplified functionality --- src/Content/Text/BBCode.php | 177 --------------------------------- src/Content/Text/Plaintext.php | 144 +++++++++++++++++++-------- src/Model/Post/Media.php | 59 +++++++---- 3 files changed, 143 insertions(+), 237 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 12fef305b1..33f91b43d1 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -209,183 +209,6 @@ class BBCode ); } - public static function getAttachedData(string $body, array $item = []): array - { - /* - - text: - - type: link, video, photo - - title: - - url: - - image: - - description: - - (thumbnail) - */ - - DI::profiler()->startRecording('rendering'); - $has_title = !empty($item['title']); - $plink = $item['plink'] ?? ''; - $post = self::getAttachmentData($body); - - // Get all linked images with alternative image description - if (preg_match_all("/\[img=(http[^\[\]]*)\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) { - foreach ($pictures as $picture) { - if ($id = Photo::getIdForName($picture[1])) { - $post['images'][] = ['url' => str_replace('-1.', '-0.', $picture[1]), 'description' => $picture[2], 'id' => $id]; - } else { - $post['remote_images'][] = ['url' => $picture[1], 'description' => $picture[2]]; - } - } - if (!empty($post['images']) && !empty($post['images'][0]['description'])) { - $post['image_description'] = $post['images'][0]['description']; - } - } - - if (preg_match_all("/\[img\]([^\[\]]*)\[\/img\]/Usi", $body, $pictures, PREG_SET_ORDER)) { - foreach ($pictures as $picture) { - if ($id = Photo::getIdForName($picture[1])) { - $post['images'][] = ['url' => str_replace('-1.', '-0.', $picture[1]), 'description' => '', 'id' => $id]; - } else { - $post['remote_images'][] = ['url' => $picture[1], 'description' => '']; - } - } - } - - if (!isset($post['type'])) { - $post['text'] = $body; - } - - // Simplify image codes - $post['text'] = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $post['text']); - $post['text'] = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $post['text']); - - // if nothing is found, it maybe having an image. - if (!isset($post['type'])) { - if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img\]([^\[]+?)\[/img\]\s*\[/url\]#ism", $post['text'], $pictures, PREG_SET_ORDER)) { - if ((count($pictures) == 1) && !$has_title) { - if (!empty($item['object-type']) && ($item['object-type'] == Activity\ObjectType::IMAGE)) { - // Replace the preview picture with the real picture - $url = str_replace('-1.', '-0.', $pictures[0][2]); - $data = ['url' => $url, 'type' => 'photo']; - } else { - // Checking, if the link goes to a picture - $data = ParseUrl::getSiteinfoCached($pictures[0][1]); - } - - // Workaround: - // Sometimes photo posts to the own album are not detected at the start. - // So we seem to cannot use the cache for these cases. That's strange. - if (($data['type'] != 'photo') && strstr($pictures[0][1], '/photos/')) { - $data = ParseUrl::getSiteinfo($pictures[0][1]); - } - - if ($data['type'] == 'photo') { - $post['type'] = 'photo'; - if (isset($data['images'][0])) { - $post['image'] = $data['images'][0]['src']; - $post['url'] = $data['url']; - } else { - $post['image'] = $data['url']; - } - - $post['preview'] = $pictures[0][2]; - $post['text'] = trim(str_replace($pictures[0][0], '', $post['text'])); - } else { - $imgdata = Images::getInfoFromURLCached($pictures[0][1]); - if (($imgdata) && substr($imgdata['mime'], 0, 6) == 'image/') { - $post['type'] = 'photo'; - $post['image'] = $pictures[0][1]; - $post['preview'] = $pictures[0][2]; - $post['text'] = trim(str_replace($pictures[0][0], '', $post['text'])); - } - } - } elseif (count($pictures) > 0) { - if (count($pictures) > 4) { - $post['type'] = 'link'; - $post['url'] = $plink; - } else { - $post['type'] = 'photo'; - } - - $post['image'] = $pictures[0][2]; - - foreach ($pictures as $picture) { - $post['text'] = trim(str_replace($picture[0], '', $post['text'])); - } - } - } elseif (preg_match_all("(\[img\](.*?)\[\/img\])ism", $post['text'], $pictures, PREG_SET_ORDER)) { - if ($has_title) { - $post['type'] = 'link'; - $post['url'] = $plink; - } else { - $post['type'] = 'photo'; - } - - $post['image'] = $pictures[0][1]; - foreach ($pictures as $picture) { - $post['text'] = trim(str_replace($picture[0], '', $post['text'])); - } - } - - // Test for the external links - preg_match_all("(\[url\](.*?)\[\/url\])ism", $post['text'], $links1, PREG_SET_ORDER); - preg_match_all("(\[url\=(.*?)\].*?\[\/url\])ism", $post['text'], $links2, PREG_SET_ORDER); - - $links = array_merge($links1, $links2); - - // If there is only a single one, then use it. - // This should cover link posts via API. - if ((count($links) == 1) && !isset($post['preview']) && !$has_title) { - $post['type'] = 'link'; - $post['url'] = $links[0][1]; - } - - // Simplify "video" element - $post['text'] = preg_replace('(\[video.*?\ssrc\s?=\s?([^\s\]]+).*?\].*?\[/video\])ism', '[video]$1[/video]', $post['text']); - - // Now count the number of external media links - preg_match_all("(\[vimeo\](.*?)\[\/vimeo\])ism", $post['text'], $links1, PREG_SET_ORDER); - preg_match_all("(\[youtube\\](.*?)\[\/youtube\\])ism", $post['text'], $links2, PREG_SET_ORDER); - preg_match_all("(\[video\\](.*?)\[\/video\\])ism", $post['text'], $links3, PREG_SET_ORDER); - preg_match_all("(\[audio\\](.*?)\[\/audio\\])ism", $post['text'], $links4, PREG_SET_ORDER); - - // Add them to the other external links - $links = array_merge($links, $links1, $links2, $links3, $links4); - - // Are there more than one? - if (count($links) > 1) { - // The post will be the type "text", which means a blog post - unset($post['type']); - $post['url'] = $plink; - } - - if (!isset($post['type'])) { - $post['type'] = 'text'; - } - - if (($post['type'] == 'photo') && empty($post['images']) && !empty($post['remote_images'])) { - $post['images'] = $post['remote_images']; - $post['image'] = $post['images'][0]['url']; - if (!empty($post['images']) && !empty($post['images'][0]['description'])) { - $post['image_description'] = $post['images'][0]['description']; - } - } - unset($post['remote_images']); - } elseif (isset($post['url']) && ($post['type'] == 'video')) { - $data = ParseUrl::getSiteinfoCached($post['url']); - - if (isset($data['images'][0])) { - $post['image'] = $data['images'][0]['src']; - } - } elseif (preg_match_all("#\[url=([^\]]+?)\]\s*\[img\]([^\[]+?)\[/img\]\s*\[/url\]#ism", $post['text'], $pictures, PREG_SET_ORDER)) { - foreach ($pictures as $picture) { - $post['text'] = trim(str_replace($picture[0], '', $post['text'])); - } - } - - DI::profiler()->stopRecording(); - return $post; - } - /** * Remove [attachment] BBCode * diff --git a/src/Content/Text/Plaintext.php b/src/Content/Text/Plaintext.php index c72dad2be5..ce0a305fe7 100644 --- a/src/Content/Text/Plaintext.php +++ b/src/Content/Text/Plaintext.php @@ -23,7 +23,10 @@ namespace Friendica\Content\Text; use Friendica\Core\Protocol; use Friendica\DI; +use Friendica\Model\Photo; +use Friendica\Model\Post; use Friendica\Util\Network; +use Friendica\Util\Strings; class Plaintext { @@ -109,30 +112,15 @@ class Plaintext * @param int $limit The maximum number of characters when posting to that network * @param bool $includedlinks Has an attached link to be included into the message? * @param int $htmlmode This controls the behavior of the BBCode conversion - * @param string $target_network Name of the network where the post should go to. * * @return array Same array structure than \Friendica\Content\Text\BBCode::getAttachedData * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @see \Friendica\Content\Text\BBCode::getAttachedData */ - public static function getPost(array $item, int $limit = 0, bool $includedlinks = false, int $htmlmode = BBCode::MASTODON_API, string $target_network = '') + public static function getPost(array $item, int $limit = 0, bool $includedlinks = false, int $htmlmode = BBCode::MASTODON_API) { - // Remove hashtags - $URLSearchString = '^\[\]'; - $body = preg_replace("/([#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $item['body']); - - // Add an URL element if the text contains a raw link - $body = preg_replace( - '/([^\]\=\'"]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism', - '$1[url]$2[/url]', - $body - ); - - // Remove the abstract - $body = BBCode::stripAbstract($body); - - // At first look at data that is attached via "type-..." stuff - $post = BBCode::getAttachedData($body, $item); + // Fetch attached media information + $post = self::getPostMedia($item); if (($item['title'] != '') && ($post['text'] != '')) { $post['text'] = trim($item['title'] . "\n\n" . $post['text']); @@ -140,34 +128,21 @@ class Plaintext $post['text'] = trim($item['title']); } - $abstract = ''; - // Fetch the abstract from the given target network - if ($target_network != '') { - $default_abstract = BBCode::getAbstract($item['body']); - $abstract = BBCode::getAbstract($item['body'], $target_network); + switch ($htmlmode) { + case BBCode::TWITTER: + $abstract = BBCode::getAbstract($item['body'], Protocol::TWITTER); + break; - // If we post to a network with no limit we only fetch - // an abstract exactly for this network - if (($limit == 0) && ($abstract == $default_abstract)) { - $abstract = ''; - } - } else { // Try to guess the correct target network - switch ($htmlmode) { - case BBCode::TWITTER: - $abstract = BBCode::getAbstract($item['body'], Protocol::TWITTER); - break; + case BBCode::OSTATUS: + $abstract = BBCode::getAbstract($item['body'], Protocol::STATUSNET); + break; - case BBCode::OSTATUS: - $abstract = BBCode::getAbstract($item['body'], Protocol::STATUSNET); - break; - - default: // We don't know the exact target. - // We fetch an abstract since there is a posting limit. - if ($limit > 0) { - $abstract = BBCode::getAbstract($item['body']); - } - } + default: // We don't know the exact target. + // We fetch an abstract since there is a posting limit. + if ($limit > 0) { + $abstract = BBCode::getAbstract($item['body']); + } } if ($abstract != '') { @@ -323,4 +298,87 @@ class Plaintext return $parts; } + + /** + * Fetch attached media to the post and simplify the body. + * + * @param array $item + * @return array + */ + private static function getPostMedia(array $item): array + { + $post = ['type' => 'text', 'images' => [], 'remote_images' => []]; + + // Remove mentions and hashtag links + $URLSearchString = '^\[\]'; + $post['text'] = preg_replace("/([#!@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $item['body']); + + // Remove abstract + $post['text'] = BBCode::stripAbstract($post['text']); + // Remove attached links + $post['text'] = BBCode::removeAttachment($post['text']); + // Remove any links + $post['text'] = Post\Media::removeFromBody($post['text']); + + $images = Post\Media::getByURIId($item['uri-id'], [Post\Media::IMAGE]); + if (!empty($item['quote-uri-id'])) { + $images = array_merge($images, Post\Media::getByURIId($item['quote-uri-id'], [Post\Media::IMAGE])); + } + foreach ($images as $image) { + if ($id = Photo::getIdForName($image['url'])) { + $post['images'][] = ['url' => $image['url'], 'description' => $image['description'], 'id' => $id]; + } else { + $post['remote_images'][] = ['url' => $image['url'], 'description' => $image['description']]; + } + } + + if (empty($post['images'])) { + unset($post['images']); + } + + if (empty($post['remote_images'])) { + unset($post['remote_images']); + } + + if (!empty($post['images'])) { + $post['type'] = 'photo'; + $post['image'] = $post['images'][0]['url']; + $post['image_description'] = $post['images'][0]['description']; + } elseif (!empty($post['remote_images'])) { + $post['type'] = 'photo'; + $post['image'] = $post['remote_images'][0]['url']; + $post['image_description'] = $post['remote_images'][0]['description']; + } + + // Look for audio or video links + $media = Post\Media::getByURIId($item['uri-id'], [Post\Media::AUDIO, Post\Media::VIDEO]); + if (!empty($item['quote-uri-id'])) { + $media = array_merge($media, Post\Media::getByURIId($item['quote-uri-id'], [Post\Media::AUDIO, Post\Media::VIDEO])); + } + + foreach ($media as $medium) { + if (in_array($medium['type'], [Post\Media::AUDIO, Post\Media::VIDEO])) { + $post['type'] = 'link'; + $post['url'] = $medium['url']; + } + } + + // Look for an attached link + $page = Post\Media::getByURIId($item['uri-id'], [Post\Media::HTML]); + if (!empty($item['quote-uri-id']) && empty($page)) { + $page = Post\Media::getByURIId($item['quote-uri-id'], [Post\Media::HTML]); + } + if (!empty($page)) { + $post['type'] = 'link'; + $post['url'] = $page[0]['url']; + $post['description'] = $page[0]['description']; + $post['title'] = $page[0]['name']; + + if (empty($post['image']) && !empty($page[0]['preview'])) { + $post['image'] = $page[0]['preview']; + } + } + + return $post; + } } diff --git a/src/Model/Post/Media.php b/src/Model/Post/Media.php index ab17789724..dd3f9f36e7 100644 --- a/src/Model/Post/Media.php +++ b/src/Model/Post/Media.php @@ -463,7 +463,7 @@ class Media */ private static function isPictureLink(string $page, string $preview): bool { - return preg_match('#/photos/.*/image/#ism', $page) && preg_match('#/photo/.*-1\.#ism', $preview); + return (preg_match('#/photo/.*-0\.#ism', $page) || preg_match('#/photos/.*/image/#ism', $page)) && preg_match('#/photo/.*-[01]\.#ism', $preview); } /** @@ -482,15 +482,20 @@ class Media $attachments = []; if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]\s*\[/url\]$endmatchpattern#ism", $body, $pictures, PREG_SET_ORDER)) { foreach ($pictures as $picture) { - if (!self::isPictureLink($picture[1], $picture[2])) { - continue; + if (self::isPictureLink($picture[1], $picture[2])) { + $body = str_replace($picture[0], '', $body); + $image = str_replace('-1.', '-0.', $picture[2]); + $attachments[$image] = [ + 'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image, + 'preview' => $picture[2], 'description' => $picture[3] + ]; + } else { + $body = str_replace($picture[0], '', $body); + $attachments[$picture[1]] = [ + 'uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $picture[1], + 'preview' => $picture[2], 'description' => $picture[3] + ]; } - $body = str_replace($picture[0], '', $body); - $image = str_replace('-1.', '-0.', $picture[2]); - $attachments[$image] = [ - 'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image, - 'preview' => $picture[2], 'description' => $picture[3] - ]; } } @@ -503,15 +508,20 @@ class Media if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img\]([^\[]+?)\[/img\]\s*\[/url\]$endmatchpattern#ism", $body, $pictures, PREG_SET_ORDER)) { foreach ($pictures as $picture) { - if (!self::isPictureLink($picture[1], $picture[2])) { - continue; + if (self::isPictureLink($picture[1], $picture[2])) { + $body = str_replace($picture[0], '', $body); + $image = str_replace('-1.', '-0.', $picture[2]); + $attachments[$image] = [ + 'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image, + 'preview' => $picture[2], 'description' => null + ]; + } else { + $body = str_replace($picture[0], '', $body); + $attachments[$picture[1]] = [ + 'uri-id' => $uriid, 'type' => self::UNKNOWN, 'url' => $picture[1], + 'preview' => $picture[2], 'description' => null + ]; } - $body = str_replace($picture[0], '', $body); - $image = str_replace('-1.', '-0.', $picture[2]); - $attachments[$image] = [ - 'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image, - 'preview' => $picture[2], 'description' => null - ]; } } @@ -567,6 +577,21 @@ class Media return $body; } + /** + * Remove media from the body + * + * @param string $body + * @return string + */ + public static function removeFromBody(string $body): string + { + do { + $prebody = $body; + $body = self::insertFromBody(0, $body); + } while ($prebody != $body); + return $body; + } + /** * Add media links from a relevant url in the body * From 14c5b207429d804894d137c100abc4cce249fcf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Mon, 13 Mar 2023 10:48:16 +0100 Subject: [PATCH 6/7] move upload-button in filebrowser above previews its annoying, when you open filebrowser to upload an image or file, and the button moves away under your finger/cursor, in case of loading preview images slower than the form itself. just change position of button (class="upload") and browser itself (class="media") disannoys the behaviour. --- view/theme/frio/templates/media/browser.tpl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/view/theme/frio/templates/media/browser.tpl b/view/theme/frio/templates/media/browser.tpl index 71974eeea8..37581b805b 100644 --- a/view/theme/frio/templates/media/browser.tpl +++ b/view/theme/frio/templates/media/browser.tpl @@ -22,6 +22,10 @@ +
+ +
+
{{* List of photo albums *}} @@ -52,9 +56,6 @@
-
- -
{{* This part contains the conent loader icon which is visible when new conent is loaded *}} From 1d6637335639685c0745de9bbfb3f3411270146f Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Mon, 13 Mar 2023 21:22:33 +0100 Subject: [PATCH 7/7] bump version to 2023.03-rc --- VERSION | 2 +- database.sql | 2 +- src/App.php | 2 +- view/lang/C/messages.po | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index f0bc8ce38a..4f66207d10 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2023.03-dev +2023.03-rc diff --git a/database.sql b/database.sql index e05a420fa8..ec4f86309e 100644 --- a/database.sql +++ b/database.sql @@ -1,5 +1,5 @@ -- ------------------------------------------ --- Friendica 2023.03-dev (Giant Rhubarb) +-- Friendica 2023.03-rc (Giant Rhubarb) -- DB_UPDATE_VERSION 1517 -- ------------------------------------------ diff --git a/src/App.php b/src/App.php index 792df0f748..d36eb253a7 100644 --- a/src/App.php +++ b/src/App.php @@ -64,7 +64,7 @@ class App { const PLATFORM = 'Friendica'; const CODENAME = 'Giant Rhubarb'; - const VERSION = '2023.03-dev'; + const VERSION = '2023.03-rc'; // Allow themes to control internal parameters // by changing App values in theme.php diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 1d8a5a33d5..3825ceac85 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -6,7 +6,7 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: 2023.03-dev\n" +"Project-Id-Version: 2023.03-rc\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2023-02-18 20:49+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"