]> git.mxchange.org Git - friendica.git/blobdiff - src/Module/Settings/Profile/Photo/Index.php
Introduce `Response` for Modules to create a testable way for module responses
[friendica.git] / src / Module / Settings / Profile / Photo / Index.php
index 9cb5644b2a168b156778ff21bf355f7032af210c..309a893e666b618cea848f5c8aab6e8095e2fd06 100644 (file)
@@ -1,22 +1,40 @@
 <?php
+/**
+ * @copyright Copyright (C) 2010-2021, the Friendica project
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Module\Settings\Profile\Photo;
 
-use Friendica\App\Arguments;
 use Friendica\Core\Renderer;
 use Friendica\Core\Session;
 use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Photo;
-use Friendica\Module\BaseSettingsModule;
+use Friendica\Module\BaseSettings;
 use Friendica\Network\HTTPException;
 use Friendica\Object\Image;
 use Friendica\Util\Images;
 use Friendica\Util\Strings;
 
-class Index extends BaseSettingsModule
+class Index extends BaseSettings
 {
-       public static function post(array $parameters = [])
+       protected function post(array $request = [], array $post = [])
        {
                if (!Session::isAuthenticated()) {
                        return;
@@ -33,9 +51,8 @@ class Index extends BaseSettingsModule
                $filename = basename($_FILES['userfile']['name']);
                $filesize = intval($_FILES['userfile']['size']);
                $filetype = $_FILES['userfile']['type'];
-               if ($filetype == '') {
-                       $filetype = Images::guessType($filename);
-               }
+
+               $filetype = Images::getMimeTypeBySource($src, $filename, $filetype);
 
                $maximagesize = DI::config()->get('system', 'maximagesize', 0);
 
@@ -75,15 +92,13 @@ class Index extends BaseSettingsModule
 
                $filename = '';
 
-               if (Photo::store($Image, local_user(), 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 0)) {
-                       info(DI::l10n()->t('Image uploaded successfully.'));
-               } else {
+               if (!Photo::store($Image, local_user(), 0, $resource_id, $filename, DI::l10n()->t(Photo::PROFILE_PHOTOS), 0, Photo::USER_AVATAR)) {
                        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, Photo::USER_AVATAR)) {
                                notice(DI::l10n()->t('Image size reduction [%s] failed.', '640'));
                        }
                }
@@ -91,7 +106,7 @@ class Index extends BaseSettingsModule
                DI::baseUrl()->redirect('settings/profile/photo/crop/' . $resource_id);
        }
 
-       public static function content(array $parameters = [])
+       protected function content(array $request = []): string
        {
                if (!Session::isAuthenticated()) {
                        throw new HTTPException\ForbiddenException(DI::l10n()->t('Permission denied.'));
@@ -99,7 +114,6 @@ class Index extends BaseSettingsModule
 
                parent::content();
 
-               /** @var Arguments $args */
                $args = DI::args();
 
                $newuser = $args->get($args->getArgc() - 1) === 'new';
@@ -119,7 +133,7 @@ class Index extends BaseSettingsModule
                                DI::l10n()->t('or'),
                                ($newuser) ?
                                        '<a href="' . DI::baseUrl() . '">' . DI::l10n()->t('skip this step') . '</a>'
-                                       : '<a href="' . DI::baseUrl() . '/photos/' . DI::app()->user['nickname'] . '">'
+                                       : '<a href="' . DI::baseUrl() . '/photos/' . DI::app()->getLoggedInUserNickname() . '">'
                                                . DI::l10n()->t('select a photo from your photo albums') . '</a>'
                        ),
                ]);