]> git.mxchange.org Git - friendica.git/blob - src/Module/Api/Twitter/Account/UpdateProfileImage.php
spelling: days
[friendica.git] / src / Module / Api / Twitter / Account / UpdateProfileImage.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Api\Twitter\Account;
23
24 use Friendica\Module\BaseApi;
25 use Friendica\DI;
26 use Friendica\Model\Photo;
27 use Friendica\Network\HTTPException;
28
29 /**
30  * updates the profile image for the user (either a specified profile or the default profile)
31  *
32  * @see https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_image
33  */
34 class UpdateProfileImage extends BaseApi
35 {
36         protected function post(array $request = [])
37         {
38                 BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
39                 $uid = BaseApi::getCurrentUserID();
40
41                 // get mediadata from image or media (Twitter call api/account/update_profile_image provides image)
42                 if (!empty($_FILES['image'])) {
43                         $media = $_FILES['image'];
44                 } elseif (!empty($_FILES['media'])) {
45                         $media = $_FILES['media'];
46                 }
47
48                 // error if image data is missing
49                 if (empty($media)) {
50                         throw new HTTPException\BadRequestException('no media data submitted');
51                 }
52
53                 // save new profile image
54                 $resource_id = Photo::uploadAvatar($uid, $media);
55                 if (empty($resource_id)) {
56                         throw new HTTPException\InternalServerErrorException('image upload failed');
57                 }
58
59                 // output for client
60                 $skip_status = $this->getRequestValue($request, 'skip_status', false);
61
62                 $user_info = DI::twitterUser()->createFromUserId($uid, $skip_status)->toArray();
63
64                 // "verified" isn't used here in the standard
65                 unset($user_info['verified']);
66
67                 // "uid" is only needed for some internal stuff, so remove it from here
68                 unset($user_info['uid']);
69
70                 $this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null);
71         }
72 }