*/
use Friendica\App;
-use Friendica\Collection\Api\Notifications as ApiNotifications;
use Friendica\Content\ContactSelector;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\HTML;
use Friendica\Model\Profile;
use Friendica\Model\User;
use Friendica\Model\Verb;
+use Friendica\Module\Api\ApiResponse;
use Friendica\Module\BaseApi;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\BadRequestException;
use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Network\HTTPException\TooManyRequestsException;
use Friendica\Network\HTTPException\UnauthorizedException;
-use Friendica\Object\Api\Friendica\Notification as ApiNotification;
use Friendica\Object\Image;
use Friendica\Protocol\Activity;
use Friendica\Security\BasicAuth;
Logger::warning(API_LOG_PREFIX . 'not implemented', ['module' => 'api', 'action' => 'call', 'query' => DI::args()->getQueryString()]);
throw new NotFoundException();
} catch (HTTPException $e) {
- header("HTTP/1.1 {$e->getCode()} {$e->getDescription()}");
- return api_error($type, $e, $args);
+ DI::apiResponse()->error($e->getCode(), $e->getDescription(), $e->getMessage(), $type);
}
}
-/**
- * Format API error string
- *
- * @param string $type Return type (xml, json, rss, as)
- * @param object $e HTTPException Error object
- * @param App\Arguments $args The App arguments
- * @return string|array error message formatted as $type
- */
-function api_error($type, $e, App\Arguments $args)
-{
- $error = ($e->getMessage() !== "" ? $e->getMessage() : $e->getDescription());
- /// @TODO: https://dev.twitter.com/overview/api/response-codes
-
- $error = ["error" => $error,
- "code" => $e->getCode() . " " . $e->getDescription(),
- "request" => $args->getQueryString()];
-
- $return = BaseApi::formatData('status', $type, ['status' => $error]);
-
- switch ($type) {
- case "xml":
- header("Content-Type: text/xml");
- break;
- case "json":
- header("Content-Type: application/json");
- $return = json_encode($return);
- break;
- case "rss":
- header("Content-Type: application/rss+xml");
- break;
- case "atom":
- header("Content-Type: application/atom+xml");
- break;
- }
-
- return $return;
-}
-
/**
* Set values for RSS template
*
if (!empty(DI::args()->getArgv()[$argid])) {
$data = explode(".", DI::args()->getArgv()[$argid]);
if (count($data) > 1) {
- list($user, $null) = $data;
+ [$user, $null] = $data;
}
}
if (is_numeric($user)) {
unset($user_info["uid"]);
unset($user_info["self"]);
- return BaseApi::formatData("user", $type, ['user' => $user_info]);
+ return DI::apiResponse()->formatData("user", $type, ['user' => $user_info]);
}
/// @TODO move to top of file or somewhere better
Logger::info(API_LOG_PREFIX . 'End', ['action' => 'get_status', 'status_info' => $status_info]);
- return BaseApi::formatData('statuses', $type, ['status' => $status_info]);
+ return DI::apiResponse()->formatData('statuses', $type, ['status' => $status_info]);
}
/**
unset($user_info['uid']);
unset($user_info['self']);
- return BaseApi::formatData('user', $type, ['user' => $user_info]);
+ return DI::apiResponse()->formatData('user', $type, ['user' => $user_info]);
}
/// @TODO move to top of file or somewhere better
throw new BadRequestException('No search term specified.');
}
- return BaseApi::formatData('users', $type, $userlist);
+ return DI::apiResponse()->formatData('users', $type, $userlist);
}
/// @TODO move to top of file or somewhere better
throw new NotFoundException;
}
- return BaseApi::formatData("users", $type, ['users' => $users]);
+ return DI::apiResponse()->formatData("users", $type, ['users' => $users]);
}
/// @TODO move to top of file or somewhere better
DBA::close($tags);
if (empty($uriids)) {
- return BaseApi::formatData('statuses', $type, $data);
+ return DI::apiResponse()->formatData('statuses', $type, $data);
}
$condition = ['uri-id' => $uriids];
bindComments($data['status']);
- return BaseApi::formatData('statuses', $type, $data);
+ return DI::apiResponse()->formatData('statuses', $type, $data);
}
/// @TODO move to top of file or somewhere better
break;
}
- return BaseApi::formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, $data);
}
break;
}
- return BaseApi::formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, $data);
}
/// @TODO move to top of file or somewhere better
break;
}
- return BaseApi::formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, $data);
}
/// @TODO move to top of file or somewhere better
if ($conversation) {
$data = ['status' => $ret];
- return BaseApi::formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, $data);
} else {
$data = ['status' => $ret[0]];
- return BaseApi::formatData("status", $type, $data);
+ return DI::apiResponse()->formatData("status", $type, $data);
}
}
$ret = api_format_items(Post::toArray($statuses), $user_info, false, $type);
$data = ['status' => $ret];
- return BaseApi::formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, $data);
}
/// @TODO move to top of file or somewhere better
break;
}
- return BaseApi::formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, $data);
}
/// @TODO move to top of file or somewhere better
break;
}
- return BaseApi::formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, $data);
}
/// @TODO move to top of file or somewhere better
break;
}
- return BaseApi::formatData("status", $type, $data);
+ return DI::apiResponse()->formatData("status", $type, $data);
}
/// @TODO move to top of file or somewhere better
break;
}
- return BaseApi::formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, $data);
}
/// @TODO move to top of file or somewhere better
}
foreach ((array)$items as $item) {
- list($status_user, $author_user, $owner_user) = api_item_get_user($a, $item);
+ [$status_user, $author_user, $owner_user] = api_item_get_user($a, $item);
// Look if the posts are matching if they should be filtered by user id
if ($filter_user && ($status_user["id"] != $user_info["id"])) {
$a = Friendica\DI::app();
if (empty($status_user) || empty($author_user) || empty($owner_user)) {
- list($status_user, $author_user, $owner_user) = api_item_get_user($a, $item);
+ [$status_user, $author_user, $owner_user] = api_item_get_user($a, $item);
}
DI::contentItem()->localize($item);
{
$ret = [];
/// @TODO $ret is not filled here?
- return BaseApi::formatData('lists', $type, ["lists_list" => $ret]);
+ return DI::apiResponse()->formatData('lists', $type, ["lists_list" => $ret]);
}
/// @TODO move to top of file or somewhere better
'mode' => $mode
];
}
- return BaseApi::formatData("lists", $type, ['lists' => ['lists' => $lists]]);
+ return DI::apiResponse()->formatData("lists", $type, ['lists' => ['lists' => $lists]]);
}
/// @TODO move to top of file or somewhere better
break;
}
- return BaseApi::formatData("statuses", $type, $data);
+ return DI::apiResponse()->formatData("statuses", $type, $data);
}
/// @TODO move to top of file or somewhere better
if ($data === false) {
return false;
}
- return BaseApi::formatData("users", $type, $data);
+ return DI::apiResponse()->formatData("users", $type, $data);
}
/**
if ($data === false) {
return false;
}
- return BaseApi::formatData("users", $type, $data);
+ return DI::apiResponse()->formatData("users", $type, $data);
}
/// @TODO move to top of file or somewhere better
if ($data === false) {
return false;
}
- return BaseApi::formatData("users", $type, $data);
+ return DI::apiResponse()->formatData("users", $type, $data);
}
/// @TODO move to top of file or somewhere better
$ids[] = $user['id'];
}
- return BaseApi::formatData("ids", $type, ['id' => $ids]);
+ return DI::apiResponse()->formatData("ids", $type, ['id' => $ids]);
}
/// @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 BaseApi::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.
*
break;
}
- return BaseApi::formatData("direct-messages", $type, $data);
+ return DI::apiResponse()->formatData("direct-messages", $type, $data);
}
/// @TODO move to top of file or somewhere better
// error if no id or parenturi specified (for clients posting parent-uri as well)
if ($verbose == "true" && ($id == 0 || $parenturi == "")) {
$answer = ['result' => 'error', 'message' => 'message id or parenturi not specified'];
- return BaseApi::formatData("direct_messages_delete", $type, ['$result' => $answer]);
+ return DI::apiResponse()->formatData("direct_messages_delete", $type, ['$result' => $answer]);
}
// BadRequestException if no id specified (for clients using Twitter API)
if (!DBA::exists('mail', ["`uid` = ? AND `id` = ? " . $sql_extra, $uid, $id])) {
if ($verbose == "true") {
$answer = ['result' => 'error', 'message' => 'message id not in database'];
- return BaseApi::formatData("direct_messages_delete", $type, ['$result' => $answer]);
+ return DI::apiResponse()->formatData("direct_messages_delete", $type, ['$result' => $answer]);
}
/// @todo BadRequestException ok for Twitter API clients?
throw new BadRequestException('message id not in database');
if ($result) {
// return success
$answer = ['result' => 'ok', 'message' => 'message deleted'];
- return BaseApi::formatData("direct_message_delete", $type, ['$result' => $answer]);
+ return DI::apiResponse()->formatData("direct_message_delete", $type, ['$result' => $answer]);
} else {
$answer = ['result' => 'error', 'message' => 'unknown error'];
- return BaseApi::formatData("direct_messages_delete", $type, ['$result' => $answer]);
+ return DI::apiResponse()->formatData("direct_messages_delete", $type, ['$result' => $answer]);
}
}
/// @todo return JSON data like Twitter API not yet implemented
// Set screen_name since Twidere requests it
$contact['screen_name'] = $contact['nick'];
- return BaseApi::formatData('friendships-destroy', $type, ['user' => $contact]);
+ return DI::apiResponse()->formatData('friendships-destroy', $type, ['user' => $contact]);
}
+
api_register_func('api/friendships/destroy', 'api_friendships_destroy', true, API_METHOD_POST);
/**
));
if ($verbose == "true" && !DBA::isResult($r)) {
$answer = ['result' => 'error', 'message' => 'no mails available'];
- return BaseApi::formatData("direct_messages_all", $type, ['$result' => $answer]);
+ return DI::apiResponse()->formatData("direct_messages_all", $type, ['$result' => $answer]);
}
$ret = [];
break;
}
- return BaseApi::formatData("direct-messages", $type, $data);
+ return DI::apiResponse()->formatData("direct-messages", $type, $data);
}
/**
api_register_func('api/direct_messages/sent', 'api_direct_messages_sentbox', true);
api_register_func('api/direct_messages', 'api_direct_messages_inbox', true);
-/**
- * delete a complete photoalbum with all containing photos from database through api
- *
- * @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
- * @return string|array
- * @throws BadRequestException
- * @throws ForbiddenException
- * @throws InternalServerErrorException
- */
-function api_fr_photoalbum_delete($type)
-{
- if (api_user() === false) {
- throw new ForbiddenException();
- }
- // input params
- $album = $_REQUEST['album'] ?? '';
-
- // we do not allow calls without album string
- if ($album == "") {
- throw new BadRequestException("no albumname specified");
- }
- // check if album is existing
-
- $photos = DBA::selectToArray('photo', ['resource-id'], ['uid' => api_user(), 'album' => $album], ['group_by' => ['resource-id']]);
- if (!DBA::isResult($photos)) {
- throw new BadRequestException("album not available");
- }
-
- $resourceIds = array_column($photos, 'resource-id');
-
- // function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore
- // to the user and the contacts of the users (drop_items() performs the federation of the deletion to other networks
- $condition = ['uid' => api_user(), 'resource-id' => $resourceIds, 'type' => 'photo'];
- Item::deleteForUser($condition, api_user());
-
- // now let's delete all photos from the album
- $result = Photo::delete(['uid' => api_user(), 'album' => $album]);
-
- // return success of deletion or error message
- if ($result) {
- $answer = ['result' => 'deleted', 'message' => 'album `' . $album . '` with all containing photos has been deleted.'];
- return BaseApi::formatData("photoalbum_delete", $type, ['$result' => $answer]);
- } else {
- throw new InternalServerErrorException("unknown error - deleting from database failed");
- }
-}
-
-/**
- * update the name of the album for all photos of an album
- *
- * @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
- * @return string|array
- * @throws BadRequestException
- * @throws ForbiddenException
- * @throws InternalServerErrorException
- */
-function api_fr_photoalbum_update($type)
-{
- if (api_user() === false) {
- throw new ForbiddenException();
- }
- // input params
- $album = $_REQUEST['album'] ?? '';
- $album_new = $_REQUEST['album_new'] ?? '';
-
- // we do not allow calls without album string
- if ($album == "") {
- throw new BadRequestException("no albumname specified");
- }
- if ($album_new == "") {
- throw new BadRequestException("no new albumname specified");
- }
- // check if album is existing
- if (!Photo::exists(['uid' => api_user(), 'album' => $album])) {
- throw new BadRequestException("album not available");
- }
- // now let's update all photos to the albumname
- $result = Photo::update(['album' => $album_new], ['uid' => api_user(), 'album' => $album]);
-
- // return success of updating or error message
- if ($result) {
- $answer = ['result' => 'updated', 'message' => 'album `' . $album . '` with all containing photos has been renamed to `' . $album_new . '`.'];
- return BaseApi::formatData("photoalbum_update", $type, ['$result' => $answer]);
- } else {
- throw new InternalServerErrorException("unknown error - updating in database failed");
- }
-}
-
-
/**
* list all photos of the authenticated user
*
}
}
}
- return BaseApi::formatData("photos", $type, $data);
+ return DI::apiResponse()->formatData("photos", $type, $data);
}
/**
// return success of updating or error message
if (!is_null($data)) {
- return BaseApi::formatData("photo_create", $type, $data);
+ return DI::apiResponse()->formatData("photo_create", $type, $data);
} else {
throw new InternalServerErrorException("unknown error - uploading photo failed, see Friendica log for more information");
}
$media = $_FILES['media'];
$data = save_media_to_database("photo", $media, $type, $album, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $desc, Photo::DEFAULT, $visibility, $photo_id);
if (!is_null($data)) {
- return BaseApi::formatData("photo_update", $type, $data);
+ return DI::apiResponse()->formatData("photo_update", $type, $data);
}
}
// return success of updating or error message
if ($result) {
$answer = ['result' => 'updated', 'message' => 'Image id `' . $photo_id . '` has been updated.'];
- return BaseApi::formatData("photo_update", $type, ['$result' => $answer]);
+ return DI::apiResponse()->formatData("photo_update", $type, ['$result' => $answer]);
} else {
if ($nothingtodo) {
$answer = ['result' => 'cancelled', 'message' => 'Nothing to update for image id `' . $photo_id . '`.'];
- return BaseApi::formatData("photo_update", $type, ['$result' => $answer]);
+ return DI::apiResponse()->formatData("photo_update", $type, ['$result' => $answer]);
}
throw new InternalServerErrorException("unknown error - update photo entry in database failed");
}
throw new InternalServerErrorException("unknown error - this error on uploading or updating a photo should never happen");
}
-/**
- * delete a single photo from the database through api
- *
- * @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
- * @return string|array
- * @throws BadRequestException
- * @throws ForbiddenException
- * @throws InternalServerErrorException
- */
-function api_fr_photo_delete($type)
-{
- if (api_user() === false) {
- throw new ForbiddenException();
- }
-
- // input params
- $photo_id = $_REQUEST['photo_id'] ?? null;
-
- // do several checks on input parameters
- // we do not allow calls without photo id
- if ($photo_id == null) {
- throw new BadRequestException("no photo_id specified");
- }
-
- // check if photo is existing in database
- if (!Photo::exists(['resource-id' => $photo_id, 'uid' => api_user()])) {
- throw new BadRequestException("photo not available");
- }
-
- // now we can perform on the deletion of the photo
- $result = Photo::delete(['uid' => api_user(), 'resource-id' => $photo_id]);
-
- // return success of deletion or error message
- if ($result) {
- // function for setting the items to "deleted = 1" which ensures that comments, likes etc. are not shown anymore
- // to the user and the contacts of the users (drop_items() do all the necessary magic to avoid orphans in database and federate deletion)
- $condition = ['uid' => api_user(), 'resource-id' => $photo_id, 'type' => 'photo'];
- Item::deleteForUser($condition, api_user());
-
- $result = ['result' => 'deleted', 'message' => 'photo with id `' . $photo_id . '` has been deleted from server.'];
- return BaseApi::formatData("photo_delete", $type, ['$result' => $result]);
- } else {
- throw new InternalServerErrorException("unknown error on deleting photo from database table");
- }
-}
-
-
/**
* returns the details of a specified photo id, if scale is given, returns the photo data in base 64
*
// prepare json/xml output with data from database for the requested photo
$data = prepare_photo_data($type, $scale, $photo_id);
- return BaseApi::formatData("photo_detail", $type, $data);
+ return DI::apiResponse()->formatData("photo_detail", $type, $data);
}
}
// place api-register for photoalbum calls before 'api/friendica/photo', otherwise this function is never reached
-api_register_func('api/friendica/photoalbum/delete', 'api_fr_photoalbum_delete', true, API_METHOD_DELETE);
-api_register_func('api/friendica/photoalbum/update', 'api_fr_photoalbum_update', true, API_METHOD_POST);
api_register_func('api/friendica/photos/list', 'api_fr_photos_list', true);
api_register_func('api/friendica/photo/create', 'api_fr_photo_create_update', true, API_METHOD_POST);
api_register_func('api/friendica/photo/update', 'api_fr_photo_create_update', true, API_METHOD_POST);
-api_register_func('api/friendica/photo/delete', 'api_fr_photo_delete', true, API_METHOD_DELETE);
api_register_func('api/friendica/photo', 'api_fr_photo_detail', true);
api_register_func('api/account/update_profile_image', 'api_account_update_profile_image', true, API_METHOD_POST);
}
$grps[] = ['name' => $rr['name'], 'gid' => $rr['id'], $user_element => $users];
}
- return BaseApi::formatData("groups", $type, ['group' => $grps]);
+ return DI::apiResponse()->formatData("groups", $type, ['group' => $grps]);
}
-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 BaseApi::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);
+api_register_func('api/friendica/group_show', 'api_friendica_group_show', true);
/**
* Delete a group.
'user' => $user_info
];
- return BaseApi::formatData("lists", $type, ['lists' => $list]);
+ return DI::apiResponse()->formatData("lists", $type, ['lists' => $list]);
}
}
+
api_register_func('api/lists/destroy', 'api_lists_destroy', true, API_METHOD_DELETE);
/**
$success = group_create($name, $uid, $users);
- return BaseApi::formatData("group_create", $type, ['result' => $success]);
+ return DI::apiResponse()->formatData("group_create", $type, ['result' => $success]);
}
+
api_register_func('api/friendica/group_create', 'api_friendica_group_create', true, API_METHOD_POST);
/**
'user' => $user_info
];
- return BaseApi::formatData("lists", $type, ['lists'=>$grp]);
+ return DI::apiResponse()->formatData("lists", $type, ['lists' => $grp]);
}
}
+
api_register_func('api/lists/create', 'api_lists_create', true, API_METHOD_POST);
/**
// return success message incl. missing users in array
$status = ($erroraddinguser ? "missing user" : "ok");
$success = ['success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers];
- return BaseApi::formatData("group_update", $type, ['result' => $success]);
+ return DI::apiResponse()->formatData("group_update", $type, ['result' => $success]);
}
api_register_func('api/friendica/group_update', 'api_friendica_group_update', true, API_METHOD_POST);
'user' => $user_info
];
- return BaseApi::formatData("lists", $type, ['lists' => $list]);
+ return DI::apiResponse()->formatData("lists", $type, ['lists' => $list]);
}
}
api_register_func('api/lists/update', 'api_lists_update', true, API_METHOD_POST);
-/**
- *
- * @param string $type Return type (atom, rss, xml, json)
- *
- * @return array|string
- * @throws BadRequestException
- * @throws ForbiddenException
- * @throws ImagickException
- * @throws InternalServerErrorException
- */
-function api_friendica_activity($type)
-{
- $a = DI::app();
-
- if (api_user() === false) {
- throw new ForbiddenException();
- }
- $verb = strtolower(DI::args()->getArgv()[3]);
- $verb = preg_replace("|\..*$|", "", $verb);
-
- $id = $_REQUEST['id'] ?? 0;
-
- $res = Item::performActivity($id, $verb, api_user());
-
- if ($res) {
- if ($type == "xml") {
- $ok = "true";
- } else {
- $ok = "ok";
- }
- return BaseApi::formatData('ok', $type, ['ok' => $ok]);
- } else {
- throw new BadRequestException('Error adding activity');
- }
-}
-
-/// @TODO move to top of file or somewhere better
-api_register_func('api/friendica/activity/like', 'api_friendica_activity', true, API_METHOD_POST);
-api_register_func('api/friendica/activity/dislike', 'api_friendica_activity', true, API_METHOD_POST);
-api_register_func('api/friendica/activity/attendyes', 'api_friendica_activity', true, API_METHOD_POST);
-api_register_func('api/friendica/activity/attendno', 'api_friendica_activity', true, API_METHOD_POST);
-api_register_func('api/friendica/activity/attendmaybe', 'api_friendica_activity', true, API_METHOD_POST);
-api_register_func('api/friendica/activity/unlike', 'api_friendica_activity', true, API_METHOD_POST);
-api_register_func('api/friendica/activity/undislike', 'api_friendica_activity', true, API_METHOD_POST);
-api_register_func('api/friendica/activity/unattendyes', 'api_friendica_activity', true, API_METHOD_POST);
-api_register_func('api/friendica/activity/unattendno', 'api_friendica_activity', true, API_METHOD_POST);
-api_register_func('api/friendica/activity/unattendmaybe', 'api_friendica_activity', true, API_METHOD_POST);
-
-/**
- * Returns notifications
- *
- * @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
- *
- * @return string|array
- * @throws ForbiddenException
- * @throws BadRequestException
- * @throws Exception
- */
-function api_friendica_notification($type)
-{
- if (api_user() === false) {
- throw new ForbiddenException();
- }
- if (DI::args()->getArgc()!==3) {
- throw new BadRequestException('Invalid argument count');
- }
-
- $Notifies = DI::notify()->selectAllForUser(local_user(), 50);
-
- $notifications = new ApiNotifications();
- foreach ($Notifies as $Notify) {
- $notifications[] = new ApiNotification($Notify);
- }
-
- if ($type == 'xml') {
- $xmlnotes = [];
- foreach ($notifications as $notification) {
- $xmlnotes[] = ['@attributes' => $notification->toArray()];
- }
-
- $result = $xmlnotes;
- } elseif (count($notifications) > 0) {
- $result = $notifications->getArrayCopy();
- } else {
- $result = false;
- }
-
- return BaseApi::formatData('notes', $type, ['note' => $result]);
-}
-
/**
* Set notification as seen and returns associated item (if possible)
*
// we found the item, return it to the user
$ret = api_format_items([$item], $user_info, false, $type);
$data = ['status' => $ret];
- return BaseApi::formatData('status', $type, $data);
+ return DI::apiResponse()->formatData('status', $type, $data);
}
// the item can't be found, but we set the notification as seen, so we count this as a success
}
- return BaseApi::formatData('result', $type, ['result' => 'success']);
+ return DI::apiResponse()->formatData('result', $type, ['result' => 'success']);
} catch (NotFoundException $e) {
throw new BadRequestException('Invalid argument', $e);
} catch (Exception $e) {
/// @TODO move to top of file or somewhere better
api_register_func('api/friendica/notification/seen', 'api_friendica_notification_seen', true, API_METHOD_POST);
-api_register_func('api/friendica/notification', 'api_friendica_notification', true, API_METHOD_GET);
-
-/**
- * update a direct_message to seen state
- *
- * @param string $type Known types are 'atom', 'rss', 'xml' and 'json'
- * @return string|array (success result=ok, error result=error with error message)
- * @throws BadRequestException
- * @throws ForbiddenException
- * @throws ImagickException
- * @throws InternalServerErrorException
- * @throws UnauthorizedException
- */
-function api_friendica_direct_messages_setseen($type)
-{
- $a = DI::app();
- if (api_user() === false) {
- throw new ForbiddenException();
- }
-
- // params
- $user_info = api_get_user();
- $uid = $user_info['uid'];
- $id = $_REQUEST['id'] ?? 0;
-
- // return error if id is zero
- if ($id == "") {
- $answer = ['result' => 'error', 'message' => 'message id not specified'];
- return BaseApi::formatData("direct_messages_setseen", $type, ['$result' => $answer]);
- }
-
- // error message if specified id is not in database
- if (!DBA::exists('mail', ['id' => $id, 'uid' => $uid])) {
- $answer = ['result' => 'error', 'message' => 'message id not in database'];
- return BaseApi::formatData("direct_messages_setseen", $type, ['$result' => $answer]);
- }
-
- // update seen indicator
- $result = DBA::update('mail', ['seen' => true], ['id' => $id]);
-
- if ($result) {
- // return success
- $answer = ['result' => 'ok', 'message' => 'message set to seen'];
- return BaseApi::formatData("direct_message_setseen", $type, ['$result' => $answer]);
- } else {
- $answer = ['result' => 'error', 'message' => 'unknown error'];
- return BaseApi::formatData("direct_messages_setseen", $type, ['$result' => $answer]);
- }
-}
-
-/// @TODO move to top of file or somewhere better
-api_register_func('api/friendica/direct_messages_setseen', 'api_friendica_direct_messages_setseen', true);
/**
* search for direct_messages containing a searchstring through api
// error if no searchstring specified
if ($searchstring == "") {
$answer = ['result' => 'error', 'message' => 'searchstring not specified'];
- return BaseApi::formatData("direct_messages_search", $type, ['$result' => $answer]);
+ return DI::apiResponse()->formatData("direct_messages_search", $type, ['$result' => $answer]);
}
// get data for the specified searchstring
$success = ['success' => true, 'search_results' => $ret];
}
- return BaseApi::formatData("direct_message_search", $type, ['$result' => $success]);
+ return DI::apiResponse()->formatData("direct_message_search", $type, ['$result' => $success]);
}
/// @TODO move to top of file or somewhere better
api_register_func('api/friendica/direct_messages_search', 'api_friendica_direct_messages_search', true);
-/**
- * Returns a list of saved searches.
- *
- * @see https://developer.twitter.com/en/docs/accounts-and-users/manage-account-settings/api-reference/get-saved_searches-list
- *
- * @param string $type Return format: json or xml
- *
- * @return string|array
- * @throws Exception
- */
-function api_saved_searches_list($type)
-{
- $terms = DBA::select('search', ['id', 'term'], ['uid' => local_user()]);
-
- $result = [];
- while ($term = DBA::fetch($terms)) {
- $result[] = [
- 'created_at' => api_date(time()),
- 'id' => intval($term['id']),
- 'id_str' => $term['id'],
- 'name' => $term['term'],
- 'position' => null,
- 'query' => $term['term']
- ];
- }
-
- DBA::close($terms);
-
- return BaseApi::formatData("terms", $type, ['terms' => $result]);
-}
-
-/// @TODO move to top of file or somewhere better
-api_register_func('api/saved_searches/list', 'api_saved_searches_list', true);
-
/*
* Number of comments
*