$record = $addon_auth['user_record'];
} else {
$user_id = User::authenticate(trim($user), trim($password));
- if ($user_id) {
+ if ($user_id !== false) {
$record = dba::selectFirst('user', [], ['uid' => $user_id]);
}
}
break;
case "json":
header("Content-Type: application/json");
- foreach ($return as $rr) {
- $json = json_encode($rr);
- }
+ $json = json_encode(end($return));
if (x($_GET, 'callback')) {
$json = $_GET['callback'] . "(" . $json . ")";
}
// Searching for contact id with uid = 0
if (!is_null($contact_id) && (intval($contact_id) != 0)) {
- $user = dbesc(api_unique_id_to_nurl($contact_id));
+ $user = dbesc(api_unique_id_to_nurl(intval($contact_id)));
if ($user == "") {
throw new BadRequestException("User not found.");
$argid = count($called_api);
list($user, $null) = explode(".", $a->argv[$argid]);
if (is_numeric($user)) {
- $user = dbesc(api_unique_id_to_nurl($user));
+ $user = dbesc(api_unique_id_to_nurl(intval($user)));
if ($user == "") {
return false;
);
// Selecting the id by priority, friendica first
- api_best_nickname($uinfo);
+ if (is_array($uinfo)) {
+ api_best_nickname($uinfo);
+ }
// if the contact wasn't found, fetch it from the contacts with uid = 0
if (!DBM::is_result($uinfo)) {
$ret = api_create_xml($data, $root_element);
break;
case "json":
+ default:
$ret = $data;
break;
}
$status_info["entities"] = $converted["entities"];
}
- if (($lastwall['item_network'] != "") && ($status["source"] == 'web')) {
+ if (($lastwall['item_network'] != "") && ($status_info["source"] == 'web')) {
$status_info["source"] = ContactSelector::networkToName($lastwall['item_network'], $user_info['url']);
} elseif (($lastwall['item_network'] != "") && (ContactSelector::networkToName($lastwall['item_network'], $user_info['url']) != $status_info["source"])) {
$status_info["source"] = trim($status_info["source"].' ('.ContactSelector::networkToName($lastwall['item_network'], $user_info['url']).')');
// "uid" and "self" are only needed for some internal stuff, so remove it from here
unset($status_info["user"]["uid"]);
unset($status_info["user"]["self"]);
- }
- logger('status_info: '.print_r($status_info, true), LOGGER_DEBUG);
+ logger('status_info: '.print_r($status_info, true), LOGGER_DEBUG);
- if ($type == "raw") {
- return $status_info;
- }
+ if ($type == "raw") {
+ return $status_info;
+ }
- return api_format_data("statuses", $type, ['status' => $status_info]);
+ return api_format_data("statuses", $type, ['status' => $status_info]);
+ }
}
/**
$sender = $user_info;
}
- $ret[] = api_format_messages($item, $recipient, $sender);
+ if (isset($recipient) && isset($sender)) {
+ $ret[] = api_format_messages($item, $recipient, $sender);
+ }
}
$fileext = "jpg";
} elseif ($filetype == "image/png") {
$fileext = "png";
+ } else {
+ throw new InternalServerErrorException('Unsupported filetype');
}
// change specified profile or all profiles to the new resource-id
if ($is_default_profile) {
logger("photo upload: new profile image upload ended", LOGGER_DEBUG);
}
- if ($r) {
+ if (isset($r) && $r) {
// create entry in 'item'-table on new uploads to enable users to comment/like/dislike the photo
if ($photo_id == null && $mediatype == "photo") {
post_photo_item($hash, $allow_cid, $deny_cid, $allow_gid, $deny_gid, $filetype, $visibility);
{
$data = BBCode::getAttachmentData($body);
- if (!$data) {
+ if (empty($data)) {
return $body;
}
$body = "";
}
// loop through all groups and retrieve all members for adding data in the user array
+ $grps = [];
foreach ($r as $rr) {
$members = Contact::getByGroupId($rr['id']);
$users = [];
}
// return success message incl. missing users in array
- $status = ($erroraddinguser ? "missing user" : ($reactivate_group ? "reactivated" : "ok"));
+ $status = ($erroraddinguser ? "missing user" : ((isset($reactivate_group) && $reactivate_group) ? "reactivated" : "ok"));
return ['success' => true, 'gid' => $gid, 'name' => $name, 'status' => $status, 'wrong users' => $errorusers];
}
foreach ($users as $user) {
$found = ($user['cid'] == $cid ? true : false);
}
- if (!$found) {
+ if (!isset($found) || !$found) {
Group::removeMemberByName($uid, $name, $cid);
}
}
return api_format_data("lists", $type, ['lists' => $list]);
}
-
- return api_format_data("group_update", $type, ['result' => $success]);
}
api_register_func('api/lists/update', 'api_lists_update', true, API_METHOD_POST);
$sender = $user_info;
}
- $ret[] = api_format_messages($item, $recipient, $sender);
+ if (isset($recipient) && isset($sender)) {
+ $ret[] = api_format_messages($item, $recipient, $sender);
+ }
}
$success = ['success' => true, 'search_results' => $ret];
}
}
// loop through all returned profiles and retrieve data and users
$k = 0;
+ $profiles = [];
foreach ($r as $rr) {
$profile = api_format_items_profiles($rr);
// select all users from contact table, loop and prepare standard return for user data
$users = [];
- $r = q(
+ $nurls = q(
"SELECT `id`, `nurl` FROM `contact` WHERE `uid`= %d AND `profile-id` = %d",
intval(api_user()),
intval($rr['profile_id'])
);
- foreach ($r as $rr) {
- $user = api_get_user($a, $rr['nurl']);
+ foreach ($nurls as $nurl) {
+ $user = api_get_user($a, $nurl['nurl']);
($type == "xml") ? $users[$k++ . ":user"] = $user : $users[] = $user;
}
$profile['users'] = $users;