]> git.mxchange.org Git - friendica.git/commitdiff
Use a constant for the profile photo album
authorMichael <heluecht@pirati.ca>
Thu, 14 Oct 2021 04:12:00 +0000 (04:12 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 14 Oct 2021 04:12:00 +0000 (04:12 +0000)
include/api.php
mod/photos.php
src/Model/Photo.php
src/Model/User.php
src/Module/Settings/Profile/Photo/Crop.php
src/Module/Settings/Profile/Photo/Index.php
src/Object/Image.php

index c5c863bdd1ec0893c2d8150213647b43e74831aa..22a6ee432133e523108ce5cce4d5899af75b2b7e 100644 (file)
@@ -4408,7 +4408,7 @@ function api_account_update_profile_image($type)
                $media = $_FILES['media'];
        }
        // save new profile image
-       $data = save_media_to_database("profileimage", $media, $type, DI::l10n()->t('Profile Photos'), "", "", "", "", "", Photo::USER_AVATAR);
+       $data = save_media_to_database("profileimage", $media, $type, DI::l10n()->t(Photo::PROFILE_PHOTOS), "", "", "", "", "", Photo::USER_AVATAR);
 
        // get filetype
        if (is_array($media['type'])) {
index f58e5322499b0cfa4c9c9f33f04d536635b7adf1..ba964ce5fa06515ec828c6f6210824cc3d1412e5 100644 (file)
@@ -86,7 +86,7 @@ function photos_init(App $a) {
                        $ret['albums'] = [];
                        foreach ($albums as $k => $album) {
                                //hide profile photos to others
-                               if (!$is_owner && !Session::getRemoteContactID($owner['uid']) && ($album['album'] == DI::l10n()->t('Profile Photos')))
+                               if (!$is_owner && !Session::getRemoteContactID($owner['uid']) && ($album['album'] == DI::l10n()->t(Photo::PROFILE_PHOTOS)))
                                        continue;
                                $entry = [
                                        'text'      => $album['album'],
@@ -195,7 +195,7 @@ function photos_post(App $a)
                }
                $album = hex2bin(DI::args()->getArgv()[3]);
 
-               if ($album === DI::l10n()->t('Profile Photos') || $album === Photo::CONTACT_PHOTOS || $album === DI::l10n()->t(Photo::CONTACT_PHOTOS)) {
+               if ($album === DI::l10n()->t(Photo::PROFILE_PHOTOS) || $album === Photo::CONTACT_PHOTOS || $album === DI::l10n()->t(Photo::CONTACT_PHOTOS)) {
                        DI::baseUrl()->redirect($_SESSION['photo_return']);
                        return; // NOTREACHED
                }
@@ -614,7 +614,7 @@ function photos_post(App $a)
 
        $r = Photo::selectToArray([], ['`album` = ? AND `uid` = ? AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR', $album, $page_owner_uid]);
 
-       if (!DBA::isResult($r) || ($album == DI::l10n()->t('Profile Photos'))) {
+       if (!DBA::isResult($r) || ($album == DI::l10n()->t(Photo::PROFILE_PHOTOS))) {
                $visible = 1;
        } else {
                $visible = 0;
@@ -1025,7 +1025,7 @@ function photos_content(App $a)
 
                // edit album name
                if ($cmd === 'edit') {
-                       if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
+                       if (($album !== DI::l10n()->t(Photo::PROFILE_PHOTOS)) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS))) {
                                if ($can_post) {
                                        $edit_tpl = Renderer::getMarkupTemplate('album_edit.tpl');
 
@@ -1042,7 +1042,7 @@ function photos_content(App $a)
                                }
                        }
                } else {
-                       if (($album !== DI::l10n()->t('Profile Photos')) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS)) && $can_post) {
+                       if (($album !== DI::l10n()->t(Photo::PROFILE_PHOTOS)) && ($album !== Photo::CONTACT_PHOTOS) && ($album !== DI::l10n()->t(Photo::CONTACT_PHOTOS)) && $can_post) {
                                $edit = [DI::l10n()->t('Edit Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/edit'];
                                $drop = [DI::l10n()->t('Drop Album'), 'photos/' . $user['nickname'] . '/album/' . bin2hex($album) . '/drop'];
                        }
@@ -1576,7 +1576,7 @@ function photos_content(App $a)
                $twist = false;
                foreach ($r as $rr) {
                        //hide profile photos to others
-                       if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t('Profile Photos'))) {
+                       if (!$is_owner && !Session::getRemoteContactID($owner_uid) && ($rr['album'] == DI::l10n()->t(Photo::PROFILE_PHOTOS))) {
                                continue;
                        }
 
index 1fdd55926d6177e106dc2debbaee4b5e7626a748..d4d397b16d00d750505766d9184f2f583fe119a1 100644 (file)
@@ -45,6 +45,7 @@ use Friendica\Util\Strings;
 class Photo
 {
        const CONTACT_PHOTOS = 'Contact Photos';
+       const PROFILE_PHOTOS = 'Profile Photos';
 
        const DEFAULT        = 0;
        const USER_AVATAR    = 10;
@@ -563,25 +564,6 @@ class Photo
                        $image_url = DI::baseUrl() . "/photo/" . $resource_id . "-4." . $Image->getExt() . $suffix;
                        $thumb = DI::baseUrl() . "/photo/" . $resource_id . "-5." . $Image->getExt() . $suffix;
                        $micro = DI::baseUrl() . "/photo/" . $resource_id . "-6." . $Image->getExt() . $suffix;
-
-                       // Remove the cached photo
-                       $a = DI::app();
-                       $basepath = $a->getBasePath();
-
-                       if (is_dir($basepath . "/photo")) {
-                               $filename = $basepath . "/photo/" . $resource_id . "-4." . $Image->getExt();
-                               if (file_exists($filename)) {
-                                       unlink($filename);
-                               }
-                               $filename = $basepath . "/photo/" . $resource_id . "-5." . $Image->getExt();
-                               if (file_exists($filename)) {
-                                       unlink($filename);
-                               }
-                               $filename = $basepath . "/photo/" . $resource_id . "-6." . $Image->getExt();
-                               if (file_exists($filename)) {
-                                       unlink($filename);
-                               }
-                       }
                } else {
                        $photo_failure = true;
                }
index fbee73c786b527e5b10c7bd4419e8a864e855957..daa79a0a448d66aefe1779da59446957847caa10 100644 (file)
@@ -1161,7 +1161,7 @@ class User
 
                                $resource_id = Photo::newResource();
 
-                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 4);
+                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 4);
 
                                if ($r === false) {
                                        $photo_failure = true;
@@ -1169,7 +1169,7 @@ class User
 
                                $Image->scaleDown(80);
 
-                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 5);
+                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 5);
 
                                if ($r === false) {
                                        $photo_failure = true;
@@ -1177,7 +1177,7 @@ class User
 
                                $Image->scaleDown(48);
 
-                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 6);
+                               $r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 6);
 
                                if ($r === false) {
                                        $photo_failure = true;
index d9f04d8de43e7d704194b844af5af8e6d2a68731..890d397554ffcb7c2f98f3b6db9d4575402fb805 100644 (file)
@@ -98,7 +98,7 @@ class Crop extends BaseSettings
                                        0,
                                        $resource_id,
                                        $base_image['filename'],
-                                       DI::l10n()->t('Profile Photos'),
+                                       DI::l10n()->t(Photo::PROFILE_PHOTOS),
                                        4,
                                        Photo::USER_AVATAR
                                );
@@ -114,7 +114,7 @@ class Crop extends BaseSettings
                                        0,
                                        $resource_id,
                                        $base_image['filename'],
-                                       DI::l10n()->t('Profile Photos'),
+                                       DI::l10n()->t(Photo::PROFILE_PHOTOS),
                                        5,
                                        Photo::USER_AVATAR
                                );
@@ -130,7 +130,7 @@ class Crop extends BaseSettings
                                        0,
                                        $resource_id,
                                        $base_image['filename'],
-                                       DI::l10n()->t('Profile Photos'),
+                                       DI::l10n()->t(Photo::PROFILE_PHOTOS),
                                        6,
                                        Photo::USER_AVATAR
                                );
@@ -176,7 +176,7 @@ class Crop extends BaseSettings
 
                // set an already uloaded photo as profile photo
                // if photo is in 'Profile Photos', change it in db
-               if ($photos[0]['album'] == DI::l10n()->t('Profile Photos') && $havescale) {
+               if ($photos[0]['album'] == DI::l10n()->t(Photo::PROFILE_PHOTOS) && $havescale) {
                        Photo::update(['profile' => false], ['uid' => local_user()]);
 
                        Photo::update(['profile' => true], ['resource-id' => $resource_id, 'uid' => local_user()]);
index 1584fe8f632ec4e4dc4032141902036db7dba0ae..967c76e46cfcfaa6e7b3fa257544ac860ff21036 100644 (file)
@@ -92,13 +92,13 @@ class Index extends BaseSettings
 
                $filename = '';
 
-               if (!Photo::store($Image, local_user(), 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 0)) {
+               if (!Photo::store($Image, local_user(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 0)) {
                        notice(DI::l10n()->t('Image upload failed.'));
                }
 
                if ($width > 640 || $height > 640) {
                        $Image->scaleDown(640);
-                       if (!Photo::store($Image, local_user(), 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 1)) {
+                       if (!Photo::store($Image, local_user(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 1)) {
                                notice(DI::l10n()->t('Image size reduction [%s] failed.', '640'));
                        }
                }
index 8c8ebfb29d3f315e76528c7d17be48624eb0466d..dd9590369611712df969d751b3dad0f5a5b55bf7 100644 (file)
@@ -637,24 +637,6 @@ class Image
                $this->height = imagesy($this->image);
        }
 
-       /**
-        * @param string $path file path
-        * @return mixed
-        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
-        */
-       public function saveToFilePath($path)
-       {
-               if (!$this->isValid()) {
-                       return false;
-               }
-
-               $string = $this->asString();
-
-               DI::profiler()->stopRecording('file');
-               file_put_contents($path, $string);
-               DI::profiler()->stopRecording();
-       }
-
        /**
         * Magic method allowing string casting of an Image object
         *