* @param string $type Return type (atom, rss, xml, json)
* @param array $data JSON style array
*
- * @return (string|object|array) XML data or JSON data
+ * @return (string|array) XML data or JSON data
*/
function api_format_data($root_element, $type, $data)
{
*/
function api_search($type)
{
+ $a = get_app();
+ $user_info = api_get_user($a);
+
+ if (api_user() === false || $user_info === false) {
+ throw new ForbiddenException();
+ }
+
$data = [];
$sql_extra = '';
$since_id
);
- $data['status'] = api_format_items(dba::inArray($r), api_get_user(get_app()));
+ $data['status'] = api_format_items(dba::inArray($r), $user_info);
return api_format_data("statuses", $type, $data);
}
function api_statuses_home_timeline($type)
{
$a = get_app();
+ $user_info = api_get_user($a);
- if (api_user() === false) {
+ if (api_user() === false || $user_info === false) {
throw new ForbiddenException();
}
unset($_REQUEST["screen_name"]);
unset($_GET["screen_name"]);
- $user_info = api_get_user($a);
- // get last newtork messages
+ // get last network messages
// params
$count = (x($_REQUEST, 'count') ? $_REQUEST['count'] : 20);
function api_statuses_public_timeline($type)
{
$a = get_app();
+ $user_info = api_get_user($a);
- if (api_user() === false) {
+ if (api_user() === false || $user_info === false) {
throw new ForbiddenException();
}
- $user_info = api_get_user($a);
- // get last newtork messages
+ // get last network messages
// params
$count = (x($_REQUEST, 'count') ? $_REQUEST['count'] : 20);
function api_statuses_networkpublic_timeline($type)
{
$a = get_app();
+ $user_info = api_get_user($a);
- if (api_user() === false) {
+ if (api_user() === false || $user_info === false) {
throw new ForbiddenException();
}
- $user_info = api_get_user($a);
-
$since_id = x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0;
$max_id = x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0;
function api_statuses_show($type)
{
$a = get_app();
+ $user_info = api_get_user($a);
- if (api_user() === false) {
+ if (api_user() === false || $user_info === false) {
throw new ForbiddenException();
}
- $user_info = api_get_user($a);
-
// params
$id = intval($a->argv[3]);
function api_conversation_show($type)
{
$a = get_app();
+ $user_info = api_get_user($a);
- if (api_user() === false) {
+ if (api_user() === false || $user_info === false) {
throw new ForbiddenException();
}
- $user_info = api_get_user($a);
-
// params
$id = intval($a->argv[3]);
$count = (x($_REQUEST, 'count') ? $_REQUEST['count'] : 20);
function api_statuses_mentions($type)
{
$a = get_app();
+ $user_info = api_get_user($a);
- if (api_user() === false) {
+ if (api_user() === false || $user_info === false) {
throw new ForbiddenException();
}
unset($_REQUEST["screen_name"]);
unset($_GET["screen_name"]);
- $user_info = api_get_user($a);
- // get last newtork messages
-
+ // get last network messages
// params
$since_id = defaults($_REQUEST, 'since_id', 0);
function api_statuses_user_timeline($type)
{
$a = get_app();
+ $user_info = api_get_user($a);
- if (api_user() === false) {
+ if (api_user() === false || $user_info === false) {
throw new ForbiddenException();
}
- $user_info = api_get_user($a);
-
logger(
"api_statuses_user_timeline: api_user: ". api_user() .
"\nuser_info: ".print_r($user_info, true) .
global $called_api;
$a = get_app();
+ $user_info = api_get_user($a);
- if (api_user() === false) {
+ if (api_user() === false || $user_info === false) {
throw new ForbiddenException();
}
$called_api = [];
- $user_info = api_get_user($a);
-
// in friendica starred item are private
// return favorites only for self
logger('api_favorites: self:' . $user_info['self']);
$user_info = api_get_user($a);
$uid = $user_info['uid'];
- $r = q(
- "SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d",
- intval($uid)
- );
+ $groups = dba::select('group', [], ['deleted' => 0, 'uid' => $uid]);
// loop through all groups
- foreach ($r as $rr) {
- if ($rr['visible']) {
+ $lists = [];
+ foreach ($groups as $group) {
+ if ($group['visible']) {
$mode = 'public';
} else {
$mode = 'private';
}
- $grps[] = [
- 'name' => $rr['name'],
- 'id' => intval($rr['id']),
- 'id_str' => (string) $rr['id'],
+ $lists[] = [
+ 'name' => $group['name'],
+ 'id' => intval($group['id']),
+ 'id_str' => (string) $group['id'],
'user' => $user_info,
'mode' => $mode
];
}
- return api_format_data("lists", $type, ['lists' => ['lists'=>$grps]]);
+ return api_format_data("lists", $type, ['lists' => ['lists' => $lists]]);
}
/// @TODO move to top of file or somewhere better
{
$a = get_app();
- if (api_user() === false) {
+ $user_info = api_get_user($a);
+ if (api_user() === false || $user_info === false) {
throw new ForbiddenException();
}
unset($_REQUEST["screen_name"]);
unset($_GET["screen_name"]);
- $user_info = api_get_user($a);
- // get last newtork messages
+ if (empty($_REQUEST['list_id'])) {
+ throw new BadRequestException('list_id not specified');
+ }
// params
$count = (x($_REQUEST, 'count') ? $_REQUEST['count'] : 20);
}
$since_id = (x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0);
$max_id = (x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0);
- //$since_id = 0;//$since_id = (x($_REQUEST, 'since_id')?$_REQUEST['since_id'] : 0);
$exclude_replies = (x($_REQUEST, 'exclude_replies') ? 1 : 0);
$conversation_id = (x($_REQUEST, 'conversation_id') ? $_REQUEST['conversation_id'] : 0);
$sql_extra .= ' AND `item`.`parent` = ' . intval($conversation_id);
}
- $r = q(
+ $statuses = dba::p(
"SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
STRAIGHT_JOIN `group_member` ON `group_member`.`contact-id` = `item`.`contact-id`
- WHERE `item`.`uid` = %d AND `verb` = '%s'
+ WHERE `item`.`uid` = ? AND `verb` = ?
AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
$sql_extra
- AND `item`.`id`>%d
- AND `group_member`.`gid` = %d
- ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
- intval(api_user()),
- dbesc(ACTIVITY_POST),
- intval($since_id),
- intval($_REQUEST['list_id']),
- intval($start),
- intval($count)
+ AND `item`.`id`>?
+ AND `group_member`.`gid` = ?
+ ORDER BY `item`.`id` DESC LIMIT ".intval($start)." ,".intval($count),
+ api_user(),
+ ACTIVITY_POST,
+ $since_id,
+ $_REQUEST['list_id']
);
- $ret = api_format_items($r, $user_info, false, $type);
-
- // Set all posts from the query above to seen
- $idarray = [];
- foreach ($r as $item) {
- $idarray[] = intval($item["id"]);
- }
-
- $idlist = implode(",", $idarray);
+ $items = api_format_items(dba::inArray($statuses), $user_info, false, $type);
- if ($idlist != "") {
- $unseen = q("SELECT `id` FROM `item` WHERE `unseen` AND `id` IN (%s)", $idlist);
-
- if ($unseen) {
- q("UPDATE `item` SET `unseen` = 0 WHERE `unseen` AND `id` IN (%s)", $idlist);
- }
- }
-
- $data = ['status' => $ret];
+ $data = ['status' => $items];
switch ($type) {
case "atom":
case "rss":
function api_direct_messages_box($type, $box, $verbose)
{
$a = get_app();
+ $user_info = api_get_user($a);
- if (api_user() === false) {
+ if (api_user() === false || $user_info === false) {
throw new ForbiddenException();
}
unset($_REQUEST["screen_name"]);
unset($_GET["screen_name"]);
- $user_info = api_get_user($a);
$profile_url = $user_info["url"];
// pagination
*/
function prepare_photo_data($type, $scale, $photo_id)
{
+ $a = get_app();
+ $user_info = api_get_user($a);
+
+ if ($user_info === false) {
+ throw new ForbiddenException();
+ }
+
$scale_sql = ($scale === false ? "" : sprintf("AND scale=%d", intval($scale)));
$data_sql = ($scale === false ? "" : "data, ");
);
// prepare output of comments
- $commentData = api_format_items($r, api_get_user(get_app()), false, $type);
+ $commentData = api_format_items($r, $user_info, false, $type);
$comments = [];
if ($type == "xml") {
$k = 0;
}
// get data of the specified group id
- $r = q(
- "SELECT * FROM `group` WHERE `uid` = %d AND `id` = %d",
- intval($uid),
- intval($gid)
- );
+ $group = dba::selectFirst('group', [], ['uid' => $uid, 'id' => $gid]);
// error message if specified gid is not in database
- if (!DBM::is_result($r)) {
+ if (!$group) {
throw new BadRequestException('gid not available');
}
if (Group::remove($gid)) {
- $grp = [
- 'name' => $r[0]['name'],
+ $list = [
+ 'name' => $group['name'],
'id' => intval($gid),
'id_str' => (string) $gid,
'user' => $user_info
];
- return api_format_data("lists", $type, ['lists'=>$grp]);
+ return api_format_data("lists", $type, ['lists' => $list]);
}
}
api_register_func('api/lists/destroy', 'api_lists_destroy', true, API_METHOD_DELETE);
* @return array|string
* @see https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/post-lists-create
*/
-function api_list_create($type)
+function api_lists_create($type)
{
$a = get_app();
return api_format_data("lists", $type, ['lists'=>$grp]);
}
}
-api_register_func('api/lists/create', 'api_list_create', true, API_METHOD_POST);
+api_register_func('api/lists/create', 'api_lists_create', true, API_METHOD_POST);
/**
* Update the specified group with the posted array of contacts.
}
// get data of the specified group id
- $r = q(
- "SELECT * FROM `group` WHERE `uid` = %d AND `id` = %d",
- intval($uid),
- intval($gid)
- );
+ $group = dba::selectFirst('group', [], ['uid' => $uid, 'id' => $gid]);
// error message if specified gid is not in database
- if (!DBM::is_result($r)) {
+ if (!$group) {
throw new BadRequestException('gid not available');
}
if (Group::update($gid, $name)) {
- $grp = [
+ $list = [
'name' => $name,
'id' => intval($gid),
'id_str' => (string) $gid,
'user' => $user_info
];
- return api_format_data("lists", $type, ['lists'=>$grp]);
+ return api_format_data("lists", $type, ['lists' => $list]);
}
return api_format_data("group_update", $type, ['result' => $success]);
function api_friendica_notification_seen($type)
{
$a = get_app();
+ $user_info = api_get_user($a);
- if (api_user() === false) {
+ if (api_user() === false || $user_info === false) {
throw new ForbiddenException();
}
if ($a->argc!==4) {
);
if ($r!==false) {
// we found the item, return it to the user
- $user_info = api_get_user($a);
$ret = api_format_items($r, $user_info, false, $type);
$data = ['status' => $ret];
return api_format_data("status", $type, $data);