friendica/src/Module/Api/Twitter/Account/UpdateProfile.php

72 lines
2.4 KiB
PHP
Raw Normal View History

2021-11-25 00:03:34 +01:00
<?php
/**
2023-01-01 15:36:24 +01:00
* @copyright Copyright (C) 2010-2023, the Friendica project
2021-11-25 00:03:34 +01: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\Database\DBA;
use Friendica\Module\BaseApi;
use Friendica\DI;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
/**
* Update user profile
*/
class UpdateProfile extends BaseApi
{
2021-11-30 22:41:10 +01:00
protected function post(array $request = [])
2021-11-25 00:03:34 +01:00
{
BaseApi::checkAllowedScope(BaseApi::SCOPE_WRITE);
$uid = BaseApi::getCurrentUserID();
2021-11-25 00:06:28 +01:00
2021-11-25 00:03:34 +01:00
$api_user = DI::twitterUser()->createFromUserId($uid, true)->toArray();
2021-11-25 00:06:28 +01:00
2021-12-04 23:16:16 +01:00
if (!empty($request['name'])) {
DBA::update('profile', ['name' => $request['name']], ['uid' => $uid]);
DBA::update('user', ['username' => $request['name']], ['uid' => $uid]);
Contact::update(['name' => $request['name']], ['uid' => $uid, 'self' => 1]);
Contact::update(['name' => $request['name']], ['id' => $api_user['id']]);
2021-11-25 00:03:34 +01:00
}
2021-11-25 00:06:28 +01:00
2021-12-04 23:16:16 +01:00
if (isset($request['description'])) {
DBA::update('profile', ['about' => $request['description']], ['uid' => $uid]);
Contact::update(['about' => $request['description']], ['uid' => $uid, 'self' => 1]);
Contact::update(['about' => $request['description']], ['id' => $api_user['id']]);
2021-11-25 00:03:34 +01:00
}
2021-11-25 00:06:28 +01:00
2022-01-06 08:34:16 +01:00
Contact::updateSelfFromUserID($uid, true);
2021-11-25 00:03:34 +01:00
Profile::publishUpdate($uid);
2021-11-25 00:06:28 +01:00
$skip_status = $this->getRequestValue($request, 'skip_status', false);
2021-11-25 00:06:28 +01:00
2021-11-25 00:03:34 +01:00
$user_info = DI::twitterUser()->createFromUserId($uid, $skip_status)->toArray();
2021-11-25 00:06:28 +01:00
2021-11-25 00:03:34 +01:00
// "verified" isn't used here in the standard
unset($user_info["verified"]);
2021-11-25 00:06:28 +01:00
2021-11-25 00:03:34 +01:00
// "uid" is only needed for some internal stuff, so remove it from here
unset($user_info['uid']);
2021-11-25 00:06:28 +01:00
$this->response->addFormattedContent('user', ['user' => $user_info], $this->parameters['extension'] ?? null);
2021-11-25 00:03:34 +01:00
}
}