]> git.mxchange.org Git - friendica.git/commitdiff
Improved preview size
authorMichael <heluecht@pirati.ca>
Mon, 8 May 2023 21:32:38 +0000 (21:32 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 8 May 2023 21:32:38 +0000 (21:32 +0000)
src/Model/Photo.php
src/Model/Post/Media.php
src/Module/Item/Compose.php
src/Module/Media/Photo/Upload.php
src/Module/Profile/Photos.php

index 29ae473abc49b57ee72a4b43d246d0ce4cc659b2..d6039dae80f1933898b342e75199a49188649598 100644 (file)
@@ -1195,21 +1195,21 @@ class Photo
 
                $smallest = 0;
 
-               $r = self::store($image, $user['uid'], 0, $resource_id, $filename, $album, 0, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
-               if (!$r) {
+               $result = self::store($image, $user['uid'], 0, $resource_id, $filename, $album, 0, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
+               if (!$result) {
                        Logger::warning('Photo could not be stored', ['uid' => $user['uid'], 'resource_id' => $resource_id, 'filename' => $filename, 'album' => $album]);
                        return [];
                }
 
                if ($width > 640 || $height > 640) {
                        $image->scaleDown(640);
+               }
+
+               if ($width > 320 || $height > 320) {
                        $r = self::store($image, $user['uid'], 0, $resource_id, $filename, $album, 1, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
                        if ($r) {
                                $smallest = 1;
                        }
-               }
-
-               if ($width > 320 || $height > 320) {
                        $image->scaleDown(320);
                        $r = self::store($image, $user['uid'], 0, $resource_id, $filename, $album, 2, self::DEFAULT, $allow_cid, $allow_gid, $deny_cid, $deny_gid, $desc);
                        if ($r && ($smallest == 0)) {
index 4b806bcc6028c4a884aa14c521204c5919e98084..cc5b16d1e7d73f3aeb1e656cf744e0367d17f9be 100644 (file)
@@ -463,7 +463,7 @@ class Media
         */
        private static function isLinkToPhoto(string $page, string $preview): bool
        {
-               return preg_match('#/photo/.*-0\.#ism', $page) && preg_match('#/photo/.*-[01]\.#ism', $preview);
+               return preg_match('#/photo/.*-0\.#ism', $page) && preg_match('#/photo/.*-[012]\.#ism', $preview);
        }
 
        /**
@@ -475,7 +475,7 @@ class Media
         */
        private static function isLinkToImagePage(string $page, string $preview): bool
        {
-               return preg_match('#/photos/.*/image/#ism', $page) && preg_match('#/photo/.*-[01]\.#ism', $preview);
+               return preg_match('#/photos/.*/image/#ism', $page) && preg_match('#/photo/.*-[012]\.#ism', $preview);
        }
 
        /**
@@ -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.', '-0.', $picture[2]) . '][img=' . $picture[2] . ']' . $picture[3] . '[/img][/url]', $body);
+                                       $body = str_replace($picture[0], '[url=' . str_replace(['-1.', '-2.'], '-0.', $picture[2]) . '][img=' . $picture[2] . ']' . $picture[3] . '[/img][/url]', $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.', '-0.', $picture[2]) . '][img]' . $picture[2] . '[/img][/url]', $body);
+                                       $body = str_replace($picture[0], '[url=' . str_replace(['-1.', '-2.'], '-0.', $picture[2]) . '][img]' . $picture[2] . '[/img][/url]', $body);
                                }
                        }
                }
@@ -525,7 +525,7 @@ class Media
                        foreach ($pictures as $picture) {
                                if (self::isLinkToImagePage($picture[1], $picture[2])) {
                                        $body = str_replace($picture[0], '', $body);
-                                       $image = str_replace('-1.', '-0.', $picture[2]);
+                                       $image = str_replace(['-1.', '-2.'], '-0.', $picture[2]);
                                        $attachments[$image] = [
                                                'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image,
                                                'preview' => $picture[2], 'description' => $picture[3]
@@ -557,7 +557,7 @@ class Media
                        foreach ($pictures as $picture) {
                                if (self::isLinkToImagePage($picture[1], $picture[2])) {
                                        $body = str_replace($picture[0], '', $body);
-                                       $image = str_replace('-1.', '-0.', $picture[2]);
+                                       $image = str_replace(['-1.', '-2.'], '-0.', $picture[2]);
                                        $attachments[$image] = [
                                                'uri-id' => $uriid, 'type' => self::IMAGE, 'url' => $image,
                                                'preview' => $picture[2], 'description' => null
index d44fe2cd7d84e0133ebcac06a7b059dd9e9b3487..8201a61a66850c39d01ea9020a39376867230cb0 100644 (file)
@@ -191,6 +191,7 @@ class Compose extends BaseModule
                                'editalic'             => $this->l10n->t('Italic'),
                                'eduline'              => $this->l10n->t('Underline'),
                                'edquote'              => $this->l10n->t('Quote'),
+                               '$edemojis'            => $this->l10n->t('Add emojis'),
                                'edcode'               => $this->l10n->t('Code'),
                                'edimg'                => $this->l10n->t('Image'),
                                'edurl'                => $this->l10n->t('Link'),
index 988fd652e4e828c51590eb53b3f8d917d30a61be..3b1b69ef4f3a59bf6ae7d15e8a7db0dd46f68c0d 100644 (file)
@@ -207,13 +207,13 @@ class Upload extends \Friendica\BaseModule
 
                if ($width > 640 || $height > 640) {
                        $image->scaleDown(640);
+               }
+
+               if ($width > 320 || $height > 320) {
                        $result = Photo::store($image, $owner['uid'], 0, $resource_id, $filename, $album, 1, Photo::DEFAULT, $allow_cid);
                        if ($result) {
                                $smallest = 1;
                        }
-               }
-
-               if ($width > 320 || $height > 320) {
                        $image->scaleDown(320);
                        $result = Photo::store($image, $owner['uid'], 0, $resource_id, $filename, $album, 2, Photo::DEFAULT, $allow_cid);
                        if ($result && ($smallest == 0)) {
index 3e5b9d604cc303b5fc9deaa632f7072e9e04ce8b..ebbba283b2d6a61b6e2b88122c699747af2c49bd 100644 (file)
@@ -246,14 +246,19 @@ class Photos extends \Friendica\Module\BaseProfile
 
                if ($width > 640 || $height > 640) {
                        $image->scaleDown(640);
-                       Photo::store($image, $this->owner['uid'], 0, $resource_id, $filename, $album, 1, Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
-                       $smallest = 1;
                }
 
                if ($width > 320 || $height > 320) {
+                       $result = Photo::store($image, $this->owner['uid'], 0, $resource_id, $filename, $album, 1, Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
+                       if ($result) {
+                               $smallest = 1;
+                       }
+
                        $image->scaleDown(320);
-                       Photo::store($image, $this->owner['uid'], 0, $resource_id, $filename, $album, 2, Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
-                       $smallest = 2;
+                       $result = Photo::store($image, $this->owner['uid'], 0, $resource_id, $filename, $album, 2, Photo::DEFAULT, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
+                       if ($result && ($smallest == 0)) {
+                               $smallest = 2;
+                       }
                }
 
                $uri = Item::newURI();