mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-08 08:14:25 +02:00
API: The legacy API finally moved
This commit is contained in:
parent
8abf1dccf0
commit
95f085b7ac
22 changed files with 1161 additions and 1391 deletions
81
src/Module/Api/Friendica/Group/Show.php
Normal file
81
src/Module/Api/Friendica/Group/Show.php
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, 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\Api\Friendica\Group;
|
||||
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Module\BaseApi;
|
||||
use Friendica\Network\HTTPException;
|
||||
|
||||
/**
|
||||
* API endpoint: /api/friendica/group_show
|
||||
*/
|
||||
class Show extends BaseApi
|
||||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
|
||||
$uid = BaseApi::getCurrentUserID();
|
||||
$type = $this->parameters['extension'] ?? '';
|
||||
|
||||
// params
|
||||
$gid = $_REQUEST['gid'] ?? 0;
|
||||
|
||||
// get data of the specified group id or all groups if not specified
|
||||
if ($gid != 0) {
|
||||
$groups = DBA::selectToArray('group', [], ['deleted' => false, 'uid' => $uid, 'id' => $gid]);
|
||||
|
||||
// error message if specified gid is not in database
|
||||
if (!DBA::isResult($groups)) {
|
||||
throw new HTTPException\BadRequestException('gid not available');
|
||||
}
|
||||
} else {
|
||||
$groups = DBA::selectToArray('group', [], ['deleted' => false, 'uid' => $uid]);
|
||||
}
|
||||
|
||||
// loop through all groups and retrieve all members for adding data in the user array
|
||||
$grps = [];
|
||||
foreach ($groups as $rr) {
|
||||
$members = Contact\Group::getById($rr['id']);
|
||||
$users = [];
|
||||
|
||||
if ($type == 'xml') {
|
||||
$user_element = 'users';
|
||||
$k = 0;
|
||||
foreach ($members as $member) {
|
||||
$user = DI::twitterUser()->createFromContactId($member['contact-id'], $uid, true)->toArray();
|
||||
$users[$k++.':user'] = $user;
|
||||
}
|
||||
} else {
|
||||
$user_element = 'user';
|
||||
foreach ($members as $member) {
|
||||
$user = DI::twitterUser()->createFromContactId($member['contact-id'], $uid, true)->toArray();
|
||||
$users[] = $user;
|
||||
}
|
||||
}
|
||||
$grps[] = ['name' => $rr['name'], 'gid' => $rr['id'], $user_element => $users];
|
||||
}
|
||||
|
||||
$this->response->exit('group_update', ['group' => $grps], $this->parameters['extension'] ?? null);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue