2022-01-15 21:38:19 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2023-01-01 09:36:24 -05:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2022-01-15 21:38:19 +00:00
|
|
|
*
|
|
|
|
* @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\Api\Twitter\Account;
|
|
|
|
|
|
|
|
use Friendica\Module\BaseApi;
|
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Model\Photo;
|
|
|
|
use Friendica\Network\HTTPException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* updates the profile image for the user (either a specified profile or the default profile)
|
|
|
|
*
|
|
|
|
* @see https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/post-account-update_profile_image
|
|
|
|
*/
|
|
|
|
class UpdateProfileImage extends BaseApi
|
|
|
|
{
|
|
|
|
protected function post(array $request = [])
|
|
|
|
{
|
|
|
|
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
|
|
|
|
$uid = BaseApi::getCurrentUserID();
|
2022-01-16 20:17:31 +00:00
|
|
|
|
2022-01-15 21:38:19 +00:00
|
|
|
// get mediadata from image or media (Twitter call api/account/update_profile_image provides image)
|
|
|
|
if (!empty($_FILES['image'])) {
|
|
|
|
$media = $_FILES['image'];
|
|
|
|
} elseif (!empty($_FILES['media'])) {
|
|
|
|
$media = $_FILES['media'];
|
|
|
|
}
|
2022-01-16 20:17:31 +00:00
|
|
|
|
2022-01-15 21:38:19 +00:00
|
|
|
// error if image data is missing
|
|
|
|
if (empty($media)) {
|
|
|
|
throw new HTTPException\BadRequestException('no media data submitted');
|
|
|
|
}
|
2022-01-16 20:17:31 +00:00
|
|
|
|
2022-01-15 21:38:19 +00:00
|
|
|
// save new profile image
|
|
|
|
$resource_id = Photo::uploadAvatar($uid, $media);
|
|
|
|
if (empty($resource_id)) {
|
|
|
|
throw new HTTPException\InternalServerErrorException('image upload failed');
|
|
|
|
}
|
2022-01-16 20:17:31 +00:00
|
|
|
|
2022-01-15 21:38:19 +00:00
|
|
|
// output for client
|
2022-01-16 16:40:13 +00:00
|
|
|
$skip_status = $this->getRequestValue($request, 'skip_status', false);
|
2022-01-16 20:17:31 +00:00
|
|
|
|
2022-01-15 21:38:19 +00:00
|
|
|
$user_info = DI::twitterUser()->createFromUserId($uid, $skip_status)->toArray();
|
2022-01-16 20:17:31 +00:00
|
|
|
|
2022-01-15 21:38:19 +00:00
|
|
|
// "verified" isn't used here in the standard
|
|
|
|
unset($user_info['verified']);
|
2022-01-16 20:17:31 +00:00
|
|
|
|
2022-01-15 21:38:19 +00:00
|
|
|
// "uid" is only needed for some internal stuff, so remove it from here
|
|
|
|
unset($user_info['uid']);
|
2022-01-16 20:17:31 +00:00
|
|
|
|
2022-01-15 21:38:19 +00:00
|
|
|
$this->response->exit('user', ['user' => $user_info], $this->parameters['extension'] ?? null);
|
|
|
|
}
|
|
|
|
}
|