]> git.mxchange.org Git - friendica.git/commitdiff
Unifiy the creation of photo links
authorMichael <heluecht@pirati.ca>
Tue, 9 May 2023 20:44:58 +0000 (20:44 +0000)
committerMichael <heluecht@pirati.ca>
Tue, 9 May 2023 20:44:58 +0000 (20:44 +0000)
mod/photos.php
src/Model/Post/Media.php
src/Module/Media/Photo/Upload.php
src/Module/Profile/Photos.php
src/Util/Images.php

index 3d6a1d4051f1cece7072ea8b4b522ea9e59ed505..18118bcd96bf6ba3ac0fe283a9f11c7aa234ac5e 100644 (file)
@@ -375,9 +375,7 @@ function photos_post(App $a)
                        $arr['visible']       = 0;
                        $arr['origin']        = 1;
 
-                       $arr['body']          = '[url=' . DI::baseUrl() . '/photos/' . $user['nickname'] . '/image/' . $photo['resource-id'] . ']'
-                                               . '[img]' . DI::baseUrl() . '/photo/' . $photo['resource-id'] . '-' . $photo['scale'] . '.'. $ext . '[/img]'
-                                               . '[/url]';
+                       $arr['body']          = Images::getImageUrl($photo['resource-id'], $user['nickname'], $photo['scale'], $ext, '');
 
                        $item_id = Item::insert($arr);
                }
index cc5b16d1e7d73f3aeb1e656cf744e0367d17f9be..5e867d26cf50cfaa71ef35dad3fefd51659d7053 100644 (file)
@@ -489,7 +489,7 @@ class Media
                if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img=([^\[\]]*)\]([^\[\]]*)\[\/img\]\s*\[/url\]#ism", $body, $pictures, PREG_SET_ORDER)) {
                        foreach ($pictures as $picture) {
                                if (self::isLinkToImagePage($picture[1], $picture[2])) {
-                                       $body = str_replace($picture[0], '[url=' . str_replace(['-1.', '-2.'], '-0.', $picture[2]) . '][img=' . $picture[2] . ']' . $picture[3] . '[/img][/url]', $body);
+                                       $body = str_replace($picture[0], Images::getPictureUrl(str_replace(['-1.', '-2.'], '-0.', $picture[2]), $picture[2], $picture[3]), $body);
                                }
                        }
                }
@@ -497,7 +497,7 @@ class Media
                if (preg_match_all("#\[url=([^\]]+?)\]\s*\[img\]([^\[]+?)\[/img\]\s*\[/url\]#ism", $body, $pictures, PREG_SET_ORDER)) {
                        foreach ($pictures as $picture) {
                                if (self::isLinkToImagePage($picture[1], $picture[2])) {
-                                       $body = str_replace($picture[0], '[url=' . str_replace(['-1.', '-2.'], '-0.', $picture[2]) . '][img]' . $picture[2] . '[/img][/url]', $body);
+                                       $body = str_replace($picture[0], Images::getPictureUrl(str_replace(['-1.', '-2.'], '-0.', $picture[2]), $picture[2], ''), $body);
                                }
                        }
                }
@@ -1005,11 +1005,7 @@ class Media
 
                        if ($media['type'] == self::IMAGE) {
                                if (!empty($media['preview'])) {
-                                       if (!empty($media['description'])) {
-                                               $body .= "\n[url=" . $media['url'] . "][img=" . $media['preview'] . ']' . $media['description'] . '[/img][/url]';
-                                       } else {
-                                               $body .= "\n[url=" . $media['url'] . "][img]" . $media['preview'] . '[/img][/url]';
-                                       }
+                                       $body .= "\n" . Images::getPictureUrl($media['url'], $media['preview'], $media['description']);
                                } else {
                                        if (!empty($media['description'])) {
                                                $body .= "\n[img=" . $media['url'] . ']' . $media['description'] . '[/img]';
index 09d31971a475ecffb621879240e8a05c8f0f361f..8ea079c6cf82b22ed4073f6398a93bc443ed9112 100644 (file)
@@ -180,7 +180,7 @@ class Upload extends \Friendica\BaseModule
                }
 
                $this->logger->info('upload done');
-               $this->return(200, "\n\n" . '[url=' . $this->baseUrl . '/photos/' . $owner['nickname'] . '/image/' . $resource_id . '][img=' . $this->baseUrl . "/photo/$resource_id-$preview." . $image->getExt() . "][/img][/url]\n\n");
+               $this->return(200, "\n\n" . Images::getImageUrl($resource_id, $owner['nickname'], $preview, $image->getExt(), '') . "\n\n");
        }
 
        /**
index 03937c655ee582d0404516dc18f91b1e878ad4f3..720efa060b291e96906cc1109c8f8411e4081618 100644 (file)
@@ -273,9 +273,7 @@ class Photos extends \Friendica\Module\BaseProfile
                $arr['visible']       = $visible;
                $arr['origin']        = 1;
 
-               $arr['body']          = '[url=' . $this->baseUrl . '/photos/' . $this->owner['nickname'] . '/image/' . $resource_id . ']'
-                       . '[img]' . $this->baseUrl . "/photo/{$resource_id}-{$preview}.".$image->getExt() . '[/img]'
-                       . '[/url]';
+               $arr['body']          = Images::getImageUrl($resource_id, $this->owner['nickname'], $preview, $image->getExt(), '');
 
                $item_id = Item::insert($arr);
                // Update the photo albums cache
index 90d120081b66527e5682f2860e8b94dec5c7766a..08553a1a9c50012f7e105d1ad620f9bb63492db3 100644 (file)
@@ -316,4 +316,32 @@ class Images
 
                return ['width' => $dest_width, 'height' => $dest_height];
        }
+
+       /**
+        * Get a link to a an image link with a preview
+        *
+        * @param string $resource_id
+        * @param string $nickname
+        * @param integer $preview
+        * @param string $ext
+        * @param string $description
+        * @return string
+        */
+       public static function getImageUrl(string $resource_id, string $nickname, int $preview, string $ext, string $description): string
+       {
+               return '[url=' . DI::baseUrl() . '/photos/' . $nickname . '/image/' . $resource_id . '][img=' . DI::baseUrl() . '/photo/' . $resource_id . '-' . $preview. '.' . $ext . ']' . $description . '[/img][/url]';
+       }
+
+       /**
+        * Get a link to a picture with a preview
+        *
+        * @param string $photo
+        * @param string $preview
+        * @param string $description
+        * @return string
+        */
+       public static function getPictureUrl(string $photo, string $preview, string $description): string
+       {
+               return '[url=' . $photo . '][img=' . $preview . ']' . $description . '[/img][/url]';
+       }
 }