* @todo Automatically detect if incoming data is HTML or BBCode
*/
-use \Friendica\Core\Config;
+use Friendica\App;
+use Friendica\Core\Config;
require_once 'include/HTTPExceptions.php';
require_once 'include/bbcode.php';
* Contact url or False if contact id is unknown
*/
function api_unique_id_to_url($id) {
- $r = q("SELECT `url` FROM `contact` WHERE `uid` = 0 AND `id` = %d LIMIT 1",
- intval($id));
+ $r = dba::select('contact', array('url'), array('uid' => 0, 'id' => $id), array('limit' => 1));
- return (dbm::is_result($r) && $r[0]["url"]);
+ if (dbm::is_result($r)) {
+ return $r["url"];
+ } else {
+ return false;
+ }
}
/**
}
}
+ if (is_null($user) && x($_GET, 'profileurl')) {
+ $user = dbesc(normalise_link($_GET['profileurl']));
+ $nick = $user;
+ $extra_query = "AND `contact`.`nurl` = '%s' ";
+ if (api_user() !== false) {
+ $extra_query .= "AND `contact`.`uid`=".intval(api_user());
+ }
+ }
+
if (is_null($user) AND ($a->argc > (count($called_api) - 1)) AND (count($called_api) > 0)) {
$argid = count($called_api);
list($user, $null) = explode(".", $a->argv[$argid]);
/// @TODO move to top of file or somewhere better
api_register_func('api/users/show','api_users_show');
+ api_register_func('api/externalprofile/show','api_users_show');
function api_users_search($type) {
api_best_nickname($r);
$recipient = api_get_user($a, $r[0]['nurl']);
- } else
+ } else {
$recipient = api_get_user($a, $_POST['user_id']);
+ }
$replyto = '';
$sub = '';
$answer = array('result' => 'deleted', 'message' => 'album `' . $album . '` with all containing photos has been deleted.');
return api_format_data("photoalbum_delete", $type, array('$result' => $answer));
} else {
- throw new BadRequestException("unknown error - deleting from database failed");
+ throw new InternalServerErrorException("unknown error - deleting from database failed");
}
}
throw new BadRequestException("no new albumname specified");
}
// check if album is existing
- $r = q("SELECT * FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
+ $r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `album` = '%s'",
intval(api_user()),
dbesc($album));
if (!dbm::is_result($r)) {
$answer = array('result' => 'updated', 'message' => 'album `' . $album . '` with all containing photos has been renamed to `' . $album_new . '`.');
return api_format_data("photoalbum_update", $type, array('$result' => $answer));
} else {
- throw new BadRequestException("unknown error - updating in database failed");
+ throw new InternalServerErrorException("unknown error - updating in database failed");
}
}
intval(local_user())
);
$typetoext = array(
- 'image/jpeg' => 'jpg',
- 'image/png' => 'png',
- 'image/gif' => 'gif'
+ 'image/jpeg' => 'jpg',
+ 'image/png' => 'png',
+ 'image/gif' => 'gif'
);
$data = array('photo'=>array());
if (dbm::is_result($r)) {
$mode = "update";
// check if photo is existing in database
- $r = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' AND `album` = '%s'",
+ $r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' AND `album` = '%s'",
intval(api_user()),
dbesc($photo_id),
dbesc($album));
if (!is_null($data)) {
return api_format_data("photo_create", $type, $data);
} else {
- throw new BadRequestException("unknown error - uploading photo failed, see Friendica log for more information");
+ throw new InternalServerErrorException("unknown error - uploading photo failed, see Friendica log for more information");
}
}
$answer = array('result' => 'cancelled', 'message' => 'Nothing to update for image id `' . $photo_id . '`.');
return api_format_data("photo_update", $type, array('$result' => $answer));
}
- throw new BadRequestException("unknown error - update photo entry in database failed");
+ throw new InternalServerErrorException("unknown error - update photo entry in database failed");
}
}
- throw new BadRequestException("unknown error - this error on uploading or updating a photo should never happen");
+ throw new InternalServerErrorException("unknown error - this error on uploading or updating a photo should never happen");
}
throw new BadRequestException("no photo_id specified");
}
// check if photo is existing in database
- $r = q("SELECT * FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
+ $r = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
intval(api_user()),
dbesc($photo_id)
);
// check if specified profile id is valid
if ($profileid != 0) {
- $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d",
+ $r = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `id` = %d",
intval(api_user()),
intval($profileid));
// error message if specified profile id is not in database
intval(local_user())
);
} else {
- $r = q("update profile set photo = '%s', thumb = '%s' where id = %d and uid = %d",
+ $r = q("UPDATE `profile` SET `photo` = '%s', `thumb` = '%s' WHERE `id` = %d AND `uid` = %d",
dbesc(App::get_baseurl() . '/photo/' . $data['photo']['id'] . '-4.' . $filetype),
dbesc(App::get_baseurl() . '/photo/' . $data['photo']['id'] . '-5.' . $filetype),
intval($_REQUEST['profile']),