]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #7482 from annando/image-description
authorTobias Diekershoff <tobias.diekershoff@gmx.net>
Tue, 6 Aug 2019 06:21:54 +0000 (08:21 +0200)
committerGitHub <noreply@github.com>
Tue, 6 Aug 2019 06:21:54 +0000 (08:21 +0200)
Support for multiple picture posts in API and connectors

include/api.php
src/Content/Text/BBCode.php

index a7d25c83f0b8e7ed22207d56911d49f2ab1a64ac..4be0ff24afb9707959cfe1371d19ce6af4ca7640 100644 (file)
@@ -1157,19 +1157,21 @@ function api_statuses_update($type)
                }
        }
 
-       // To-Do: Multiple IDs
        if (requestdata('media_ids')) {
-               $r = q(
-                       "SELECT `resource-id`, `scale`, `nickname`, `type`, `desc` FROM `photo` INNER JOIN `user` ON `user`.`uid` = `photo`.`uid` WHERE `resource-id` IN (SELECT `resource-id` FROM `photo` WHERE `id` = %d) AND `scale` > 0 AND `photo`.`uid` = %d ORDER BY `photo`.`width` DESC LIMIT 1",
-                       intval(requestdata('media_ids')),
-                       api_user()
-               );
-               if (DBA::isResult($r)) {
-                       $phototypes = Image::supportedTypes();
-                       $ext = $phototypes[$r[0]['type']];
-                       $description = $r[0]['desc'] ?? '';
-                       $_REQUEST['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $r[0]['nickname'] . '/image/' . $r[0]['resource-id'] . ']';
-                       $_REQUEST['body'] .= '[img=' . System::baseUrl() . '/photo/' . $r[0]['resource-id'] . '-' . $r[0]['scale'] . '.' . $ext . ']' . $description . '[/img][/url]';
+               $ids = explode(',', requestdata('media_ids'));
+               foreach ($ids as $id) {
+                       $r = q(
+                               "SELECT `resource-id`, `scale`, `nickname`, `type`, `desc` FROM `photo` INNER JOIN `user` ON `user`.`uid` = `photo`.`uid` WHERE `resource-id` IN (SELECT `resource-id` FROM `photo` WHERE `id` = %d) AND `scale` > 0 AND `photo`.`uid` = %d ORDER BY `photo`.`width` DESC LIMIT 1",
+                               intval($id),
+                               api_user()
+                       );
+                       if (DBA::isResult($r)) {
+                               $phototypes = Image::supportedTypes();
+                               $ext = $phototypes[$r[0]['type']];
+                               $description = $r[0]['desc'] ?? '';
+                               $_REQUEST['body'] .= "\n\n" . '[url=' . System::baseUrl() . '/photos/' . $r[0]['nickname'] . '/image/' . $r[0]['resource-id'] . ']';
+                               $_REQUEST['body'] .= '[img=' . System::baseUrl() . '/photo/' . $r[0]['resource-id'] . '-' . $r[0]['scale'] . '.' . $ext . ']' . $description . '[/img][/url]';
+                       }
                }
        }
 
index a5cb78727cf8ad0d97ea82dfe711d5afb1a8ce4a..12497d66516ebbf44b6f127906b7c97959a6c97c 100644 (file)
@@ -264,6 +264,7 @@ class BBCode extends BaseObject
                        // Simplify image codes
                        $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);
+                       $post["text"] = $body;
 
                        if (preg_match_all("(\[url=(.*?)\]\s*\[img\](.*?)\[\/img\]\s*\[\/url\])ism", $body, $pictures, PREG_SET_ORDER)) {
                                if ((count($pictures) == 1) && !$has_title) {
@@ -308,6 +309,10 @@ class BBCode extends BaseObject
                                        $post["url"] = $plink;
                                        $post["image"] = $pictures[0][2];
                                        $post["text"] = $body;
+
+                                       foreach ($pictures as $picture) {
+                                               $post["text"] = trim(str_replace($picture[0], "", $post["text"]));
+                                       }
                                }
                        } elseif (preg_match_all("(\[img\](.*?)\[\/img\])ism", $body, $pictures, PREG_SET_ORDER)) {
                                if ((count($pictures) == 1) && !$has_title) {
@@ -319,12 +324,16 @@ class BBCode extends BaseObject
                                        $post["url"] = $plink;
                                        $post["image"] = $pictures[0][1];
                                        $post["text"] = $body;
+
+                                       foreach ($pictures as $picture) {
+                                               $post["text"] = trim(str_replace($picture[0], "", $post["text"]));
+                                       }
                                }
                        }
 
                        // Test for the external links
-                       preg_match_all("(\[url\](.*?)\[\/url\])ism", $body, $links1, PREG_SET_ORDER);
-                       preg_match_all("(\[url\=(.*?)\].*?\[\/url\])ism", $body, $links2, PREG_SET_ORDER);
+                       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);
 
@@ -332,15 +341,14 @@ class BBCode extends BaseObject
                        // This should cover link posts via API.
                        if ((count($links) == 1) && !isset($post["preview"]) && !$has_title) {
                                $post["type"] = "link";
-                               $post["text"] = trim($body);
                                $post["url"] = $links[0][1];
                        }
 
                        // Now count the number of external media links
-                       preg_match_all("(\[vimeo\](.*?)\[\/vimeo\])ism", $body, $links1, PREG_SET_ORDER);
-                       preg_match_all("(\[youtube\\](.*?)\[\/youtube\\])ism", $body, $links2, PREG_SET_ORDER);
-                       preg_match_all("(\[video\\](.*?)\[\/video\\])ism", $body, $links3, PREG_SET_ORDER);
-                       preg_match_all("(\[audio\\](.*?)\[\/audio\\])ism", $body, $links4, PREG_SET_ORDER);
+                       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);