}
if (!x($_SERVER, 'PHP_AUTH_USER')) {
- logger('API_login: ' . print_r($_SERVER,true), LOGGER_DEBUG);
+ logger('API_login: ' . print_r($_SERVER, true), LOGGER_DEBUG);
header('WWW-Authenticate: Basic realm="Friendica"');
throw new UnauthorizedException("This API requires login");
}
break;
case "json":
header("Content-Type: application/json");
- foreach ($r as $rr)
+ foreach ($r as $rr) {
$json = json_encode($rr);
- if (x($_GET, 'callback')) {
- $json = $_GET['callback'] . "(" . $json . ")";
- }
- return $json;
+ }
+ if (x($_GET, 'callback')) {
+ $json = $_GET['callback'] . "(" . $json . ")";
+ }
+ return $json;
break;
case "rss":
header("Content-Type: application/rss+xml");
$sql_extra = 'AND `thread`.`iid` <= ' . intval($max_id);
}
- $r = dba::p("SELECT " . item_fieldlists() . "
+ $r = dba::p(
+ "SELECT " . item_fieldlists() . "
FROM `thread`
STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
" . item_joins() . "
$sql_extra .= ' AND `item`.`parent` = ' . intval($conversation_id);
}
- $r = dba::p("SELECT " . item_fieldlists() . "
+ $r = dba::p(
+ "SELECT " . item_fieldlists() . "
FROM `item`
" . item_joins() . "
STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
$sql_extra = 'AND `thread`.`iid` <= ' . intval($max_id);
}
- $r = dba::p("SELECT " . item_fieldlists() . "
+ $r = dba::p(
+ "SELECT " . item_fieldlists() . "
FROM `thread`
STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
" . item_joins() . "
AND `item`.`uid` = %d AND `item`.`verb` = '%s'
AND `item`.`id`>%d $sql_extra
ORDER BY `item`.`id` DESC LIMIT %d ,%d",
- intval($id), intval(api_user()),
+ intval($id),
+ intval(api_user()),
dbesc(ACTIVITY_POST),
intval($since_id),
- intval($start), intval($count)
+ intval($start),
+ intval($count)
);
if (!DBM::is_result($r)) {
}
/// @TODO move to top of file or somwhere better
-api_register_func('api/statuses/user_timeline','api_statuses_user_timeline', true);
+api_register_func('api/statuses/user_timeline', 'api_statuses_user_timeline', true);
/**
* Star/unstar an item
throw new BadRequestException("Invalid action ".$action);
}
- $r = q("UPDATE item SET starred=%d WHERE id=%d AND uid=%d", $item[0]['starred'], $itemid, api_user());
+ $r = q("UPDATE item SET starred=%d WHERE id=%d AND uid=%d", $item[0]['starred'], $itemid, api_user());
q("UPDATE thread SET starred=%d WHERE iid=%d AND uid=%d", $item[0]['starred'], $itemid, api_user());
foreach ($images[1] as $image) {
//$start = strpos($text, $url, $offset);
$start = iconv_strpos($text, $image, 0, "UTF-8");
- if (!($start === false))
+ if (!($start === false)) {
$ordered_images[$start] = $image;
+ }
}
//$entities["media"] = array();
$offset = 0;
$display_url = str_replace(array("http://www.", "https://www."), array("", ""), $url);
$display_url = str_replace(array("http://", "https://"), array("", ""), $display_url);
- if (strlen($display_url) > 26)
+ if (strlen($display_url) > 26) {
$display_url = substr($display_url, 0, 25)."…";
+ }
$start = iconv_strpos($text, $url, $offset, "UTF-8");
if (!($start === false)) {
$xml_activities["friendica:".$k] = $v;
// add user data into xml output
$k_user = 0;
- foreach ($v as $user)
+ foreach ($v as $user) {
$xml_activities["friendica:".$k][$k_user++.":user"] = $user;
+ }
}
$activities = $xml_activities;
}
/**
* @todo use api_format_data() to return data
*/
-function api_ff_ids($type,$qtype)
+function api_ff_ids($type, $qtype)
{
$a = get_app();
$a = get_app();
- if (api_user() === false) throw new ForbiddenException();
+ if (api_user() === false) {
+ throw new ForbiddenException();
+ }
- if (!x($_POST, "text") || (!x($_POST, "screen_name") && !x($_POST, "user_id"))) return;
+ if (!x($_POST, "text") || (!x($_POST, "screen_name") && !x($_POST, "user_id"))) {
+ return;
+ }
$sender = api_get_user($a);
}
return api_format_data("direct-messages", $type, $data);
-
}
/// @TODO move to top of file or somewhere better
}
}
/// @todo return JSON data like Twitter API not yet implemented
-
}
/// @TODO move to top of file or somewhere better
intval(api_user()),
dbesc($album)
);
- if (!DBM::is_result($r))
+ if (!DBM::is_result($r)) {
throw new BadRequestException("album not available");
+ }
// 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
}
logger(
"File upload src: " . $src . " - filename: " . $filename .
- " - size: " . $filesize . " - type: " . $filetype, LOGGER_DEBUG
+ " - size: " . $filesize . " - type: " . $filetype,
+ LOGGER_DEBUG
);
// check if there was a php upload error
$posted = "";
preg_match("/posted='(.*?)'/ism", $attributes, $matches);
- if ($matches[1] != "")
+ if ($matches[1] != "") {
$posted = $matches[1];
+ }
preg_match('/posted="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "") {
$reshared_item["edited"] = $posted;
return $reshared_item;
-
}
function api_get_nick($profile)
$in_reply_to['screen_name'] = null;
if (($item['thr-parent'] != $item['uri']) && (intval($item['parent']) != intval($item['id']))) {
- $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
+ $r = q(
+ "SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1",
intval($item['uid']),
- dbesc($item['thr-parent']));
+ dbesc($item['thr-parent'])
+ );
if (DBM::is_result($r)) {
$in_reply_to['status_id'] = intval($r[0]['id']);
$in_reply_to['status_id_str'] = (string) intval($in_reply_to['status_id']);
- $r = q("SELECT `contact`.`nick`, `contact`.`name`, `contact`.`id`, `contact`.`url` FROM item
+ $r = q(
+ "SELECT `contact`.`nick`, `contact`.`name`, `contact`.`id`, `contact`.`url` FROM item
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`author-id`
WHERE `item`.`id` = %d LIMIT 1",
intval($in_reply_to['status_id'])
{
$best_contact = array();
- if (count($contact) == 0)
+ if (count($contact) == 0) {
return;
+ }
- foreach ($contacts as $contact)
+ foreach ($contacts as $contact) {
if ($contact["network"] == "") {
$contact["network"] = "dfrn";
$best_contact = array($contact);
}
+ }
- if (sizeof($best_contact) == 0)
- foreach ($contacts as $contact)
- if ($contact["network"] == "dfrn")
+ if (sizeof($best_contact) == 0) {
+ foreach ($contacts as $contact) {
+ if ($contact["network"] == "dfrn") {
$best_contact = array($contact);
+ }
+ }
+ }
- if (sizeof($best_contact) == 0)
- foreach ($contacts as $contact)
- if ($contact["network"] == "dspr")
+ if (sizeof($best_contact) == 0) {
+ foreach ($contacts as $contact) {
+ if ($contact["network"] == "dspr") {
$best_contact = array($contact);
+ }
+ }
+ }
- if (sizeof($best_contact) == 0)
- foreach ($contacts as $contact)
- if ($contact["network"] == "stat")
+ if (sizeof($best_contact) == 0) {
+ foreach ($contacts as $contact) {
+ if ($contact["network"] == "stat") {
$best_contact = array($contact);
+ }
+ }
+ }
- if (sizeof($best_contact) == 0)
- foreach ($contacts as $contact)
- if ($contact["network"] == "pump")
+ if (sizeof($best_contact) == 0) {
+ foreach ($contacts as $contact) {
+ if ($contact["network"] == "pump") {
$best_contact = array($contact);
+ }
+ }
+ }
- if (sizeof($best_contact) == 0)
- foreach ($contacts as $contact)
- if ($contact["network"] == "twit")
+ if (sizeof($best_contact) == 0) {
+ foreach ($contacts as $contact) {
+ if ($contact["network"] == "twit") {
$best_contact = array($contact);
+ }
+ }
+ }
if (sizeof($best_contact) == 1) {
$contacts = $best_contact;
{
$a = get_app();
- if (api_user() === false) throw new ForbiddenException();
+ if (api_user() === false) {
+ throw new ForbiddenException();
+ }
// params
$user_info = api_get_user($a);
intval($gid)
);
// error message if specified gid is not in database
- if (!DBM::is_result($r))
+ if (!DBM::is_result($r)) {
throw new BadRequestException("gid not available");
+ }
} else {
$r = q(
"SELECT * FROM `group` WHERE `deleted` = 0 AND `uid` = %d",
{
$a = get_app();
- if (api_user() === false) throw new ForbiddenException();
+ if (api_user() === false) {
+ throw new ForbiddenException();
+ }
// params
$user_info = api_get_user($a);
$users = $json['user'];
// error if no name specified
- if ($name == "")
+ if ($name == "") {
throw new BadRequestException('group name not specified');
+ }
// get data of the specified group name
$rname = q(
dbesc($name)
);
// error message if specified group name already exists
- if (DBM::is_result($rname))
+ if (DBM::is_result($rname)) {
throw new BadRequestException('group name already exists');
+ }
// check if specified group name is a deleted group
$rname = q(
dbesc($name)
);
// error message if specified group name already exists
- if (DBM::is_result($rname))
+ if (DBM::is_result($rname)) {
$reactivate_group = true;
+ }
// create group
$ret = Group::create($uid, $name);
{
$a = get_app();
- if (api_user() === false) throw new ForbiddenException();
+ if (api_user() === false) {
+ throw new ForbiddenException();
+ }
// params
$user_info = api_get_user($a);
$users = $json['user'];
// error if no name specified
- if ($name == "")
+ if ($name == "") {
throw new BadRequestException('group name not specified');
+ }
// error if no gid specified
- if ($gid == "")
+ if ($gid == "") {
throw new BadRequestException('gid not specified');
+ }
// remove members
$members = Contact::getByGroupId($gid);
{
$a = get_app();
- if (api_user() === false) throw new ForbiddenException();
+ if (api_user() === false) {
+ throw new ForbiddenException();
+ }
$verb = strtolower($a->argv[3]);
$verb = preg_replace("|\..*$|", "", $verb);
{
$a = get_app();
- if (api_user() === false) throw new ForbiddenException();
- if ($a->argc!==3) throw new BadRequestException("Invalid argument count");
+ if (api_user() === false) {
+ throw new ForbiddenException();
+ }
+ if ($a->argc!==3) {
+ throw new BadRequestException("Invalid argument count");
+ }
$nm = new NotificationsManager();
$notes = $nm->getAll(array(), "+seen -date", 50);
if ($type == "xml") {
$xmlnotes = array();
- foreach ($notes as $note)
+ foreach ($notes as $note) {
$xmlnotes[] = array("@attributes" => $note);
+ }
$notes = $xmlnotes;
}
{
$a = get_app();
- if (api_user() === false) throw new ForbiddenException();
- if ($a->argc!==4) throw new BadRequestException("Invalid argument count");
+ if (api_user() === false) {
+ throw new ForbiddenException();
+ }
+ if ($a->argc!==4) {
+ throw new BadRequestException("Invalid argument count");
+ }
$id = (x($_REQUEST, 'id') ? intval($_REQUEST['id']) : 0);
$nm = new NotificationsManager();
$note = $nm->getByID($id);
- if (is_null($note)) throw new BadRequestException("Invalid argument");
+ if (is_null($note)) {
+ throw new BadRequestException("Invalid argument");
+ }
$nm->setSeen($note);
if ($note['otype']=='item') {
/*
@TODO Maybe open to implement?
To.Do:
- [pagename] => api/1.1/statuses/lookup.json
- [id] => 605138389168451584
- [include_cards] => true
- [cards_platform] => Android-12
- [include_entities] => true
- [include_my_retweet] => 1
- [include_rts] => 1
- [include_reply_count] => true
- [include_descendent_reply_count] => true
+ [pagename] => api/1.1/statuses/lookup.json
+ [id] => 605138389168451584
+ [include_cards] => true
+ [cards_platform] => Android-12
+ [include_entities] => true
+ [include_my_retweet] => 1
+ [include_rts] => 1
+ [include_reply_count] => true
+ [include_descendent_reply_count] => true
(?)