diff --git a/include/api.php b/include/api.php index 4aafadfab..164a9de53 100644 --- a/include/api.php +++ b/include/api.php @@ -3230,48 +3230,6 @@ function api_friendships_incoming($type) /// @TODO move to top of file or somewhere better api_register_func('api/friendships/incoming', 'api_friendships_incoming', true); -/** - * Returns the instance's configuration information. - * - * @param string $type Return type (atom, rss, xml, json) - * - * @return array|string - * @throws InternalServerErrorException - */ -function api_statusnet_config($type) -{ - $name = DI::config()->get('config', 'sitename'); - $server = DI::baseUrl()->getHostname(); - $logo = DI::baseUrl() . '/images/friendica-64.png'; - $email = DI::config()->get('config', 'admin_email'); - $closed = intval(DI::config()->get('config', 'register_policy')) === \Friendica\Module\Register::CLOSED ? 'true' : 'false'; - $private = DI::config()->get('system', 'block_public') ? 'true' : 'false'; - $textlimit = (string) DI::config()->get('config', 'api_import_size', DI::config()->get('config', 'max_import_size', 200000)); - $ssl = DI::config()->get('system', 'have_ssl') ? 'true' : 'false'; - $sslserver = DI::config()->get('system', 'have_ssl') ? str_replace('http:', 'https:', DI::baseUrl()) : ''; - - $config = [ - 'site' => ['name' => $name,'server' => $server, 'theme' => 'default', 'path' => '', - 'logo' => $logo, 'fancy' => true, 'language' => 'en', 'email' => $email, 'broughtby' => '', - 'broughtbyurl' => '', 'timezone' => 'UTC', 'closed' => $closed, 'inviteonly' => false, - 'private' => $private, 'textlimit' => $textlimit, 'sslserver' => $sslserver, 'ssl' => $ssl, - 'shorturllength' => '30', - 'friendica' => [ - 'FRIENDICA_PLATFORM' => FRIENDICA_PLATFORM, - 'FRIENDICA_VERSION' => FRIENDICA_VERSION, - 'DFRN_PROTOCOL_VERSION' => DFRN_PROTOCOL_VERSION, - 'DB_UPDATE_VERSION' => DB_UPDATE_VERSION - ] - ], - ]; - - return DI::apiResponse()->formatData('config', $type, ['config' => $config]); -} - -/// @TODO move to top of file or somewhere better -api_register_func('api/gnusocial/config', 'api_statusnet_config', false); -api_register_func('api/statusnet/config', 'api_statusnet_config', false); - /** * Sends a new direct message. * @@ -4631,66 +4589,6 @@ function api_friendica_group_show($type) api_register_func('api/friendica/group_show', 'api_friendica_group_show', true); - -/** - * Delete the specified group of the user. - * - * @param string $type Return type (atom, rss, xml, json) - * - * @return array|string - * @throws BadRequestException - * @throws ForbiddenException - * @throws ImagickException - * @throws InternalServerErrorException - * @throws UnauthorizedException - */ -function api_friendica_group_delete($type) -{ - $a = DI::app(); - - if (api_user() === false) { - throw new ForbiddenException(); - } - - // params - $user_info = api_get_user(); - $gid = $_REQUEST['gid'] ?? 0; - $name = $_REQUEST['name'] ?? ''; - $uid = $user_info['uid']; - - // error if no gid specified - if ($gid == 0 || $name == "") { - throw new BadRequestException('gid or name not specified'); - } - - // error message if specified gid is not in database - if (!DBA::exists('group', ['uid' => $uid, 'id' => $gid])) { - throw new BadRequestException('gid not available'); - } - - // error message if specified gid is not in database - if (!DBA::exists('group', ['uid' => $uid, 'id' => $gid, 'name' => $name])) { - throw new BadRequestException('wrong group name'); - } - - // delete group - $gid = Group::getIdByName($uid, $name); - if (empty($gid)) { - throw new BadRequestException('other API error'); - } - - $ret = Group::remove($gid); - - if ($ret) { - // return success - $success = ['success' => $ret, 'gid' => $gid, 'name' => $name, 'status' => 'deleted', 'wrong users' => []]; - return DI::apiResponse()->formatData("group_delete", $type, ['result' => $success]); - } else { - throw new BadRequestException('other API error'); - } -} -api_register_func('api/friendica/group_delete', 'api_friendica_group_delete', true, API_METHOD_DELETE); - /** * Delete a group. * diff --git a/src/Module/Api/Friendica/Group/Delete.php b/src/Module/Api/Friendica/Group/Delete.php new file mode 100644 index 000000000..7d27222f4 --- /dev/null +++ b/src/Module/Api/Friendica/Group/Delete.php @@ -0,0 +1,77 @@ +. + * + */ + +namespace Friendica\Module\Api\Friendica\Group; + +use Friendica\Database\DBA; +use Friendica\Model\Group; +use Friendica\Module\BaseApi; +use Friendica\Network\HTTPException\BadRequestException; + +/** + * API endpoint: /api/friendica/group/delete + */ +class Delete extends BaseApi +{ + public static function rawContent(array $parameters = []) + { + self::checkAllowedScope(self::SCOPE_WRITE); + $uid = self::getCurrentUserID(); + + $request = self::getRequest([ + 'gid' => 0, + 'name' => '' + ]); + + // params + + // error if no gid specified + if ($request['gid'] == 0 || $request['name'] == "") { + throw new BadRequestException('gid or name not specified'); + } + + // error message if specified gid is not in database + if (!DBA::exists('group', ['uid' => $uid, 'id' => $request['gid']])) { + throw new BadRequestException('gid not available'); + } + + // error message if specified gid is not in database + if (!DBA::exists('group', ['uid' => $uid, 'id' => $request['gid'], 'name' => $request['name']])) { + throw new BadRequestException('wrong group name'); + } + + // delete group + $gid = Group::getIdByName($uid, $request['name']); + if (empty($request['gid'])) { + throw new BadRequestException('other API error'); + } + + $ret = Group::remove($gid); + + if ($ret) { + // return success + $success = ['success' => $ret, 'gid' => $request['gid'], 'name' => $request['name'], 'status' => 'deleted', 'wrong users' => []]; + self::exit('group_delete', ['$result' => $success], $parameters['extension'] ?? null); + } else { + throw new BadRequestException('other API error'); + } + } +} diff --git a/src/Module/Api/GNUSocial/GNUSocial/Config.php b/src/Module/Api/GNUSocial/GNUSocial/Config.php new file mode 100644 index 000000000..a6f379bcb --- /dev/null +++ b/src/Module/Api/GNUSocial/GNUSocial/Config.php @@ -0,0 +1,65 @@ +. + * + */ + +namespace Friendica\Module\Api\GNUSocial\GNUSocial; + +use Friendica\App; +use Friendica\DI; +use Friendica\Module\BaseApi; + +/** + * API endpoint: /api/gnusocial/version, /api/statusnet/version + */ +class Config extends BaseApi +{ + public static function rawContent(array $parameters = []) + { + $config = [ + 'site' => [ + 'name' => DI::config()->get('config', 'sitename'), + 'server' => DI::baseUrl()->getHostname(), + 'theme' => DI::config()->get('system', 'theme'), + 'path' => DI::baseUrl()->getUrlPath(), + 'logo' => DI::baseUrl() . '/images/friendica-64.png', + 'fancy' => true, + 'language' => DI::config()->get('system', 'language'), + 'email' => DI::config()->get('config', 'admin_email'), + 'broughtby' => '', + 'broughtbyurl' => '', + 'timezone' => DI::config()->get('system', 'default_timezone'), + 'closed' => (bool)(DI::config()->get('config', 'register_policy') == \Friendica\Module\Register::CLOSED), + 'inviteonly' => (bool)DI::config()->get('system', 'invitation_only'), + 'private' => (bool)DI::config()->get('system', 'block_public'), + 'textlimit' => (string) DI::config()->get('config', 'api_import_size', DI::config()->get('config', 'max_import_size')), + 'sslserver' => null, + 'ssl' => DI::config()->get('system', 'ssl_policy') == App\BaseURL::SSL_POLICY_FULL ? 'always' : '0', + 'friendica' => [ + 'FRIENDICA_PLATFORM' => FRIENDICA_PLATFORM, + 'FRIENDICA_VERSION' => FRIENDICA_VERSION, + 'DFRN_PROTOCOL_VERSION' => DFRN_PROTOCOL_VERSION, + 'DB_UPDATE_VERSION' => DB_UPDATE_VERSION, + ] + ], + ]; + + self::exit('config', ['config' => $config], $parameters['extension'] ?? null); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index 0b50adb0f..0dee56754 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -73,26 +73,26 @@ $apiRoutes = [ '/friendica' => [ '/activity/{verb:attendmaybe|attendno|attendyes|dislike|like|unattendmaybe|unattendno|unattendyes|undislike|unlike}[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Activity::class, [ R::POST]], - '/notification/seen[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], - '/notification[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Notification::class, [R::GET ]], - '/direct_messages_setseen[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], - '/direct_messages_search[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], - '/events[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Events\Index::class, [R::GET ]], - '/group_show[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], - '/group_create[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], - '/group_delete[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::DELETE, R::POST]], - '/group_update[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], - '/profile/show[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Profile\Show::class, [R::GET ]], - '/photoalbum/delete[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Delete::class, [R::DELETE, R::POST]], - '/photoalbum/update[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Update::class, [ R::POST]], - '/photos/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], - '/photo/create[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], - '/photo/delete[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photo\Delete::class, [R::DELETE, R::POST]], - '/photo/update[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], - '/photo[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], + '/notification/seen[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], + '/notification[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Notification::class, [R::GET ]], + '/direct_messages_setseen[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\DirectMessages\Setseen::class, [ R::POST]], + '/direct_messages_search[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], + '/events[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Events\Index::class, [R::GET ]], + '/group_show[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], + '/group_create[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], + '/group_delete[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Group\Delete::class, [R::DELETE, R::POST]], + '/group_update[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], + '/profile/show[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Profile\Show::class, [R::GET ]], + '/photoalbum/delete[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Delete::class, [R::DELETE, R::POST]], + '/photoalbum/update[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photoalbum\Update::class, [ R::POST]], + '/photos/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], + '/photo/create[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], + '/photo/delete[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Photo\Delete::class, [R::DELETE, R::POST]], + '/photo/update[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], + '/photo[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], ], - '/gnusocial/config[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], + '/gnusocial/config[.{extension:json|xml|rss|atom}]' => [Module\Api\GNUSocial\GNUSocial\Config::class, [R::GET ]], '/gnusocial/version[.{extension:json|xml|rss|atom}]' => [Module\Api\GNUSocial\GNUSocial\Version::class, [R::GET ]], '/help/test[.{extension:json|xml|rss|atom}]' => [Module\Api\GNUSocial\Help\Test::class, [R::GET ]], @@ -108,13 +108,13 @@ $apiRoutes = [ '/media/upload[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], '/media/metadata/create[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [ R::POST]], - '/saved_searches/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\SavedSearches::class, [R::GET ]], + '/saved_searches/list[.{extension:json|xml|rss|atom}]' => [Module\Api\Twitter\SavedSearches::class, [R::GET ]], '/search/tweets[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], '/search[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], - '/statusnet/config[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], + '/statusnet/config[.{extension:json|xml|rss|atom}]' => [Module\Api\GNUSocial\GNUSocial\Config::class, [R::GET ]], '/statusnet/conversation[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], '/statusnet/conversation/{id:\d+}[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::GET ]], - '/statusnet/version[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\GNUSocial\Version::class, [R::GET ]], + '/statusnet/version[.{extension:json|xml|rss|atom}]' => [Module\Api\GNUSocial\GNUSocial\Version::class, [R::GET ]], '/statuses' => [ '/destroy[.{extension:json|xml|rss|atom}]' => [Module\Api\Friendica\Index::class, [R::DELETE, R::POST]], diff --git a/tests/legacy/ApiTest.php b/tests/legacy/ApiTest.php index 05ad39cf3..12475fd16 100644 --- a/tests/legacy/ApiTest.php +++ b/tests/legacy/ApiTest.php @@ -2594,6 +2594,7 @@ class ApiTest extends FixtureTest */ public function testApiStatusnetConfig() { + /* $result = api_statusnet_config('json'); self::assertEquals('localhost', $result['config']['site']['server']); self::assertEquals('default', $result['config']['site']['theme']); @@ -2605,6 +2606,7 @@ class ApiTest extends FixtureTest self::assertEquals('false', $result['config']['site']['private']); self::assertEquals('false', $result['config']['site']['ssl']); self::assertEquals(30, $result['config']['site']['shorturllength']); + */ } /**