Merge remote-tracking branch 'upstream/develop' into quit-on-error

This commit is contained in:
Michael 2018-06-11 03:15:59 +00:00
commit b02cdc8a7f
464 changed files with 47242 additions and 57792 deletions

View file

@ -54,7 +54,7 @@ define('API_METHOD_POST', 'POST,PUT');
define('API_METHOD_DELETE', 'POST,DELETE');
$API = [];
$called_api = null;
$called_api = [];
/**
* It is not sufficient to use local_user() to check whether someone is allowed to use the API,
@ -492,7 +492,7 @@ function api_rss_extra(App $a, $arr, $user_info)
*/
function api_unique_id_to_nurl($id)
{
$r = dba::selectFirst('contact', ['nurl'], ['uid' => 0, 'id' => $id]);
$r = dba::selectFirst('contact', ['nurl'], ['id' => $id]);
if (DBM::is_result($r)) {
return $r["nurl"];
@ -532,7 +532,7 @@ function api_get_user(App $a, $contact_id = null)
$user = dbesc(api_unique_id_to_nurl(intval($contact_id)));
if ($user == "") {
throw new BadRequestException("User not found.");
throw new BadRequestException("User ID ".$contact_id." not found.");
}
$url = $user;
@ -546,7 +546,7 @@ function api_get_user(App $a, $contact_id = null)
$user = dbesc(api_unique_id_to_nurl($_GET['user_id']));
if ($user == "") {
throw new BadRequestException("User not found.");
throw new BadRequestException("User ID ".$_GET['user_id']." not found.");
}
$url = $user;
@ -670,13 +670,14 @@ function api_get_user(App $a, $contact_id = null)
'statusnet_profile_url' => $r[0]["url"],
'uid' => 0,
'cid' => Contact::getIdForURL($r[0]["url"], api_user(), true),
'pid' => Contact::getIdForURL($r[0]["url"], 0, true),
'self' => 0,
'network' => $r[0]["network"],
];
return $ret;
} else {
throw new BadRequestException("User not found.");
throw new BadRequestException("User ".$url." not found.");
}
}
@ -685,14 +686,8 @@ function api_get_user(App $a, $contact_id = null)
$uinfo[0]['network'] = NETWORK_DFRN;
}
$usr = q(
"SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval(api_user())
);
$profile = q(
"SELECT * FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
intval(api_user())
);
$usr = dba::selectFirst('user', ['default-location'], ['uid' => api_user()]);
$profile = dba::selectFirst('profile', ['about'], ['uid' => api_user(), 'is-default' => true]);
/// @TODO old-lost code? (twice)
// Counting is deactivated by now, due to performance issues
@ -759,14 +754,14 @@ function api_get_user(App $a, $contact_id = null)
$pcontact_id = Contact::getIdForURL($uinfo[0]['url'], 0, true);
if (!empty($profile[0]['about'])) {
$description = $profile[0]['about'];
if (!empty($profile['about'])) {
$description = $profile['about'];
} else {
$description = $uinfo[0]["about"];
}
if (!empty($usr[0]['default-location'])) {
$location = $usr[0]['default-location'];
if (!empty($usr['default-location'])) {
$location = $usr['default-location'];
} elseif (!empty($uinfo[0]["location"])) {
$location = $uinfo[0]["location"];
} else {
@ -809,6 +804,7 @@ function api_get_user(App $a, $contact_id = null)
'statusnet_profile_url' => $uinfo[0]['url'],
'uid' => intval($uinfo[0]['uid']),
'cid' => intval($uinfo[0]['cid']),
'pid' => Contact::getIdForURL($uinfo[0]["url"], 0, true),
'self' => $uinfo[0]['self'],
'network' => $uinfo[0]['network'],
];
@ -856,16 +852,12 @@ function api_get_user(App $a, $contact_id = null)
*/
function api_item_get_user(App $a, $item)
{
$status_user = api_get_user($a, $item["author-link"]);
$status_user = api_get_user($a, $item["author-id"]);
$status_user["protected"] = (($item["allow_cid"] != "") ||
($item["allow_gid"] != "") ||
($item["deny_cid"] != "") ||
($item["deny_gid"] != "") ||
$item["private"]);
$status_user["protected"] = $item["private"];
if ($item['thr-parent'] == $item['uri']) {
$owner_user = api_get_user($a, $item["owner-link"]);
$owner_user = api_get_user($a, $item["owner-id"]);
} else {
$owner_user = $status_user;
}
@ -935,7 +927,7 @@ function api_reformat_xml(&$item, &$key)
*
* @return string The XML data
*/
function api_create_xml($data, $root_element)
function api_create_xml(array $data, $root_element)
{
$childname = key($data);
$data2 = array_pop($data);
@ -960,7 +952,7 @@ function api_create_xml($data, $root_element)
$i = 1;
foreach ($data2 as $item) {
$data4[$i++.":".$childname] = $item;
$data4[$i++ . ":" . $childname] = $item;
}
$data2 = $data4;
@ -1068,7 +1060,7 @@ function requestdata($k)
}
/**
* Waitman Gobble Mod
* Deprecated function to upload media.
*
* @param string $type Return type (atom, rss, xml, json)
*
@ -1100,14 +1092,12 @@ function api_statuses_mediap($type)
}
$txt = HTML::toBBCode($txt);
$a->argv[1]=$user_info['screen_name']; //should be set to username?
$a->argv[1] = $user_info['screen_name']; //should be set to username?
// tell wall_upload function to return img info instead of echo
$_REQUEST['hush'] = 'yeah';
$bebop = wall_upload_post($a);
$picture = wall_upload_post($a, false);
// now that we have the img url in bbcode we can add it to the status and insert the wall item.
$_REQUEST['body'] = $txt . "\n\n" . $bebop;
$_REQUEST['body'] = $txt . "\n\n" . '[url=' . $picture["albumpage"] . '][img]' . $picture["preview"] . "[/img][/url]";
item_post($a);
// this should output the last post (the one we just posted).
@ -1256,10 +1246,9 @@ function api_statuses_update($type)
if (x($_FILES, 'media')) {
// upload the image if we have one
$_REQUEST['hush'] = 'yeah'; //tell wall_upload function to return img info instead of echo
$media = wall_upload_post($a);
if (strlen($media) > 0) {
$_REQUEST['body'] .= "\n\n" . $media;
$picture = wall_upload_post($a, false);
if (is_array($picture)) {
$_REQUEST['body'] .= "\n\n" . '[url=' . $picture["albumpage"] . '][img]' . $picture["preview"] . "[/img][/url]";
}
}
@ -1356,31 +1345,17 @@ function api_status_show($type)
logger('api_status_show: user_info: '.print_r($user_info, true), LOGGER_DEBUG);
if ($type == "raw") {
$privacy_sql = "AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''";
$privacy_sql = "AND NOT `private`";
} else {
$privacy_sql = "";
}
// get last public wall message
$lastwall = q(
"SELECT `item`.*
FROM `item`
WHERE `item`.`contact-id` = %d AND `item`.`uid` = %d
AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s')))
AND `item`.`type` != 'activity' $privacy_sql
ORDER BY `item`.`id` DESC
LIMIT 1",
intval($user_info['cid']),
intval(api_user()),
dbesc($user_info['url']),
dbesc(normalise_link($user_info['url'])),
dbesc($user_info['url']),
dbesc(normalise_link($user_info['url']))
);
$condition = ["`owner-id` = ? AND `uid` = ? AND `type` != 'activity' ".$privacy_sql,
$user_info['pid'], api_user()];
$lastwall = dba::selectFirst('item', [], $condition, ['order' => ['id' => true]]);
if (DBM::is_result($lastwall)) {
$lastwall = $lastwall[0];
$in_reply_to = api_in_reply_to($lastwall);
$converted = api_convert_item($lastwall);
@ -1428,10 +1403,10 @@ function api_status_show($type)
$status_info["entities"] = $converted["entities"];
}
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']).')');
if ($status_info["source"] == 'web') {
$status_info["source"] = ContactSelector::networkToName($lastwall['network'], $user_info['url']);
} elseif (ContactSelector::networkToName($lastwall['network'], $user_info['url']) != $status_info["source"]) {
$status_info["source"] = trim($status_info["source"].' ('.ContactSelector::networkToName($lastwall['network'], $user_info['url']).')');
}
// "uid" and "self" are only needed for some internal stuff, so remove it from here
@ -1460,28 +1435,12 @@ function api_users_show($type)
$a = get_app();
$user_info = api_get_user($a);
$lastwall = q(
"SELECT `item`.*
FROM `item`
INNER JOIN `contact` ON `contact`.`id`=`item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
WHERE `item`.`uid` = %d AND `verb` = '%s' AND `item`.`contact-id` = %d
AND ((`item`.`author-link` IN ('%s', '%s')) OR (`item`.`owner-link` IN ('%s', '%s')))
AND `type`!='activity'
AND `item`.`allow_cid`='' AND `item`.`allow_gid`='' AND `item`.`deny_cid`='' AND `item`.`deny_gid`=''
ORDER BY `id` DESC
LIMIT 1",
intval(api_user()),
dbesc(ACTIVITY_POST),
intval($user_info['cid']),
dbesc($user_info['url']),
dbesc(normalise_link($user_info['url'])),
dbesc($user_info['url']),
dbesc(normalise_link($user_info['url']))
);
$condition = ["`owner-id` = ? AND `uid` = ? AND `verb` = ? AND `type` != 'activity' AND NOT `private`",
$user_info['pid'], api_user(), ACTIVITY_POST];
$lastwall = dba::selectFirst('item', [], $condition, ['order' => ['id' => true]]);
if (DBM::is_result($lastwall)) {
$lastwall = $lastwall[0];
$in_reply_to = api_in_reply_to($lastwall);
$converted = api_convert_item($lastwall);
@ -1519,12 +1478,12 @@ function api_users_show($type)
$user_info["status"]["entities"] = $converted["entities"];
}
if (($lastwall['item_network'] != "") && ($user_info["status"]["source"] == 'web')) {
$user_info["status"]["source"] = ContactSelector::networkToName($lastwall['item_network'], $user_info['url']);
if ($user_info["status"]["source"] == 'web') {
$user_info["status"]["source"] = ContactSelector::networkToName($lastwall['network'], $user_info['url']);
}
if (($lastwall['item_network'] != "") && (ContactSelector::networkToName($lastwall['item_network'], $user_info['url']) != $user_info["status"]["source"])) {
$user_info["status"]["source"] = trim($user_info["status"]["source"] . ' (' . ContactSelector::networkToName($lastwall['item_network'], $user_info['url']) . ')');
if (ContactSelector::networkToName($lastwall['network'], $user_info['url']) != $user_info["status"]["source"]) {
$user_info["status"]["source"] = trim($user_info["status"]["source"] . ' (' . ContactSelector::networkToName($lastwall['network'], $user_info['url']) . ')');
}
}
@ -1573,10 +1532,10 @@ function api_users_search($type)
}
$userlist = ["users" => $userlist];
} else {
throw new BadRequestException("User not found.");
throw new BadRequestException("User ".$_GET["q"]." not found.");
}
} else {
throw new BadRequestException("User not found.");
throw new BadRequestException("No user specified.");
}
return api_format_data("users", $type, $userlist);
@ -1637,7 +1596,6 @@ function api_search($type)
}
$data = [];
$sql_extra = '';
if (!x($_REQUEST, 'q')) {
throw new BadRequestException("q parameter is required.");
@ -1657,24 +1615,20 @@ function api_search($type)
$start = $page * $count;
$condition = ["`verb` = ? AND `item`.`id` > ?
AND (`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))
AND `item`.`body` LIKE CONCAT('%',?,'%')",
ACTIVITY_POST, $since_id, api_user(), $_REQUEST['q']];
if ($max_id > 0) {
$sql_extra .= ' AND `item`.`id` <= ' . intval($max_id);
$condition[0] .= " AND `item`.`id` <= ?";
$condition[] = $max_id;
}
$r = dba::p(
"SELECT ".item_fieldlists()."
FROM `item` ".item_joins()."
WHERE ".item_condition()." AND (`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))
AND `item`.`body` LIKE CONCAT('%',?,'%')
$sql_extra
AND `item`.`id`>?
ORDER BY `item`.`id` DESC LIMIT ".intval($start)." ,".intval($count)." ",
api_user(),
$_REQUEST['q'],
$since_id
);
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$data['status'] = api_format_items(dba::inArray($r), $user_info);
$data['status'] = api_format_items(dba::inArray($statuses), $user_info);
return api_format_data("statuses", $type, $data);
}
@ -1724,42 +1678,30 @@ function api_statuses_home_timeline($type)
$start = $page * $count;
$sql_extra = '';
$condition = ["`uid` = ? AND `verb` = ? AND `item`.`id` > ?", api_user(), ACTIVITY_POST, $since_id];
if ($max_id > 0) {
$sql_extra .= ' AND `item`.`id` <= ' . intval($max_id);
$condition[0] .= " AND `item`.`id` <= ?";
$condition[] = $max_id;
}
if ($exclude_replies > 0) {
$sql_extra .= ' AND `item`.`parent` = `item`.`id`';
$condition[0] .= ' AND `item`.`parent` = `item`.`id`';
}
if ($conversation_id > 0) {
$sql_extra .= ' AND `item`.`parent` = ' . intval($conversation_id);
$condition[0] .= " AND `item`.`parent` = ?";
$condition[] = $conversation_id;
}
$r = q(
"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`,
`contact`.`id` AS `cid`
FROM `item`
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
WHERE `item`.`uid` = %d AND `verb` = '%s'
AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
$sql_extra
AND `item`.`id`>%d
ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
intval(api_user()),
dbesc(ACTIVITY_POST),
intval($since_id),
intval($start),
intval($count)
);
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$ret = api_format_items($r, $user_info, false, $type);
$items = dba::inArray($statuses);
$ret = api_format_items($items, $user_info, false, $type);
// Set all posts from the query above to seen
$idarray = [];
foreach ($r as $item) {
foreach ($items as $item) {
$idarray[] = intval($item["id"]);
}
@ -1819,61 +1761,35 @@ function api_statuses_public_timeline($type)
$sql_extra = '';
if ($exclude_replies && !$conversation_id) {
$condition = ["`verb` = ? AND `iid` > ? AND NOT `private` AND `wall` AND NOT `user`.`hidewall`",
ACTIVITY_POST, $since_id];
if ($max_id > 0) {
$sql_extra = 'AND `thread`.`iid` <= ' . intval($max_id);
$condition[0] .= " AND `thread`.`iid` <= ?";
$condition[] = $max_id;
}
$r = dba::p(
"SELECT " . item_fieldlists() . "
FROM `thread`
STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
" . item_joins() . "
STRAIGHT_JOIN `user` ON `user`.`uid` = `thread`.`uid`
AND NOT `user`.`hidewall`
AND `verb` = ?
AND NOT `thread`.`private`
AND `thread`.`wall`
AND `thread`.`visible`
AND NOT `thread`.`deleted`
AND NOT `thread`.`moderated`
AND `thread`.`iid` > ?
$sql_extra
ORDER BY `thread`.`iid` DESC
LIMIT " . intval($start) . ", " . intval($count),
ACTIVITY_POST,
$since_id
);
$params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
$statuses = Item::selectThread(api_user(), [], $condition, $params);
$r = dba::inArray($r);
$r = dba::inArray($statuses);
} else {
$condition = ["`verb` = ? AND `id` > ? AND NOT `private` AND `wall` AND NOT `user`.`hidewall` AND `item`.`origin`",
ACTIVITY_POST, $since_id];
if ($max_id > 0) {
$sql_extra = 'AND `item`.`id` <= ' . intval($max_id);
$condition[0] .= " AND `item`.`id` <= ?";
$condition[] = $max_id;
}
if ($conversation_id > 0) {
$sql_extra .= ' AND `item`.`parent` = ' . intval($conversation_id);
$condition[0] .= " AND `item`.`parent` = ?";
$condition[] = $conversation_id;
}
$r = dba::p(
"SELECT " . item_fieldlists() . "
FROM `item`
" . item_joins() . "
STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid`
AND NOT `user`.`hidewall`
AND `verb` = ?
AND NOT `item`.`private`
AND `item`.`wall`
AND `item`.`visible`
AND NOT `item`.`deleted`
AND NOT `item`.`moderated`
AND `item`.`id` > ?
$sql_extra
ORDER BY `item`.`id` DESC
LIMIT " . intval($start) . ", " . intval($count),
ACTIVITY_POST,
$since_id
);
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$r = dba::inArray($r);
$r = dba::inArray($statuses);
}
$ret = api_format_items($r, $user_info, false, $type);
@ -1921,33 +1837,18 @@ function api_statuses_networkpublic_timeline($type)
}
$start = ($page - 1) * $count;
$sql_extra = '';
$condition = ["`uid` = 0 AND `verb` = ? AND `thread`.`iid` > ? AND NOT `private`",
ACTIVITY_POST, $since_id];
if ($max_id > 0) {
$sql_extra = 'AND `thread`.`iid` <= ' . intval($max_id);
$condition[0] .= " AND `thread`.`iid` <= ?";
$condition[] = $max_id;
}
$r = dba::p(
"SELECT " . item_fieldlists() . "
FROM `thread`
STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
" . item_joins() . "
WHERE `thread`.`uid` = 0
AND `verb` = ?
AND NOT `thread`.`private`
AND `thread`.`visible`
AND NOT `thread`.`deleted`
AND NOT `thread`.`moderated`
AND `thread`.`iid` > ?
$sql_extra
ORDER BY `thread`.`iid` DESC
LIMIT " . intval($start) . ", " . intval($count),
ACTIVITY_POST,
$since_id
);
$params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
$statuses = Item::selectThread(api_user(), [], $condition, $params);
$r = dba::inArray($r);
$ret = api_format_items($r, $user_info, false, $type);
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
$data = ['status' => $ret];
switch ($type) {
@ -1995,13 +1896,6 @@ function api_statuses_show($type)
$conversation = (x($_REQUEST, 'conversation') ? 1 : 0);
$sql_extra = '';
if ($conversation) {
$sql_extra .= " AND `item`.`parent` = %d ORDER BY `id` ASC ";
} else {
$sql_extra .= " AND `item`.`id` = %d";
}
// try to fetch the item for the local user - or the public item, if there is no local one
$uri_item = dba::selectFirst('item', ['uri'], ['id' => $id]);
if (!DBM::is_result($uri_item)) {
@ -2015,28 +1909,22 @@ function api_statuses_show($type)
$id = $item['id'];
$r = q(
"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`,
`contact`.`id` AS `cid`
FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
WHERE `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
AND `item`.`uid` IN (0, %d) AND `item`.`verb` = '%s'
$sql_extra",
intval(api_user()),
dbesc(ACTIVITY_POST),
intval($id)
);
if ($conversation) {
$condition = ['parent' => $id, 'verb' => ACTIVITY_POST];
$params = ['order' => ['id' => true]];
} else {
$condition = ['id' => $id, 'verb' => ACTIVITY_POST];
$params = [];
}
$statuses = Item::select(api_user(), [], $condition, $params);
/// @TODO How about copying this to above methods which don't check $r ?
if (!DBM::is_result($r)) {
if (!DBM::is_result($statuses)) {
throw new BadRequestException("There is no status with this id.");
}
$ret = api_format_items($r, $user_info, false, $type);
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
if ($conversation) {
$data = ['status' => $ret];
@ -2101,38 +1989,22 @@ function api_conversation_show($type)
$id = $parent['id'];
$sql_extra = '';
$condition = ["`parent` = ? AND `uid` IN (0, ?) AND `verb` = ? AND `item`.`id` > ?",
$id, api_user(), ACTIVITY_POST, $since_id];
if ($max_id > 0) {
$sql_extra = ' AND `item`.`id` <= ' . intval($max_id);
$condition[0] .= " AND `item`.`id` <= ?";
$condition[] = $max_id;
}
$r = q(
"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`,
`contact`.`id` AS `cid`
FROM `item`
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
WHERE `item`.`parent` = %d AND `item`.`visible`
AND NOT `item`.`moderated` AND NOT `item`.`deleted`
AND `item`.`uid` IN (0, %d) AND `item`.`verb` = '%s'
AND `item`.`id`>%d $sql_extra
ORDER BY `item`.`id` DESC LIMIT %d ,%d",
intval($id),
intval(api_user()),
dbesc(ACTIVITY_POST),
intval($since_id),
intval($start),
intval($count)
);
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
if (!DBM::is_result($r)) {
throw new BadRequestException("There is no status with this id.");
if (!DBM::is_result($statuses)) {
throw new BadRequestException("There is no status with id $id.");
}
$ret = api_format_items($r, $user_info, false, $type);
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
$data = ['status' => $ret];
return api_format_data("statuses", $type, $data);
@ -2175,30 +2047,17 @@ function api_statuses_repeat($type)
logger('API: api_statuses_repeat: '.$id);
$r = q(
"SELECT `item`.*, `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`nick` as `reply_author`,
`contact`.`name`, `contact`.`photo` as `reply_photo`, `contact`.`url` as `reply_url`, `contact`.`rel`,
`contact`.`network`, `contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`contact`.`id` AS `cid`
FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
WHERE `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
AND NOT `item`.`private` AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = ''
AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = ''
AND `item`.`id`=%d",
intval($id)
);
$fields = ['body', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
$item = Item::selectFirst(api_user(), $fields, ['id' => $id, 'private' => false]);
/// @TODO other style than above functions!
if (DBM::is_result($r) && $r[0]['body'] != "") {
if (strpos($r[0]['body'], "[/share]") !== false) {
$pos = strpos($r[0]['body'], "[share");
$post = substr($r[0]['body'], $pos);
if (DBM::is_result($item) && $item['body'] != "") {
if (strpos($item['body'], "[/share]") !== false) {
$pos = strpos($item['body'], "[share");
$post = substr($item['body'], $pos);
} else {
$post = share_header($r[0]['author-name'], $r[0]['author-link'], $r[0]['author-avatar'], $r[0]['guid'], $r[0]['created'], $r[0]['plink']);
$post = share_header($item['author-name'], $item['author-link'], $item['author-avatar'], $item['guid'], $item['created'], $item['plink']);
$post .= $r[0]['body'];
$post .= $item['body'];
$post .= "[/share]";
}
$_REQUEST['body'] = $post;
@ -2216,7 +2075,7 @@ function api_statuses_repeat($type)
}
// this should output the last post (the one we just posted).
$called_api = null;
$called_api = [];
return api_status_show($type);
}
@ -2256,7 +2115,7 @@ function api_statuses_destroy($type)
$ret = api_statuses_show($type);
Item::deleteById($id);
Item::deleteForUser(['id' => $id], api_user());
return $ret;
}
@ -2299,43 +2158,19 @@ function api_statuses_mentions($type)
$start = ($page - 1) * $count;
// Ugly code - should be changed
$myurl = System::baseUrl() . '/profile/'. $a->user['nickname'];
$myurl = substr($myurl, strpos($myurl, '://') + 3);
$myurl = str_replace('www.', '', $myurl);
$sql_extra = '';
$condition = ["`uid` = ? AND `verb` = ? AND `item`.`id` > ? AND `author-id` != ?
AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `uid` = ? AND `mention` AND NOT `ignored`)",
api_user(), ACTIVITY_POST, $since_id, $user_info['pid'], api_user()];
if ($max_id > 0) {
$sql_extra .= ' AND `item`.`id` <= ' . intval($max_id);
$condition[0] .= " AND `item`.`id` <= ?";
$condition[] = $max_id;
}
$r = q(
"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`,
`contact`.`id` AS `cid`
FROM `item` FORCE INDEX (`uid_id`)
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
WHERE `item`.`uid` = %d AND `verb` = '%s'
AND NOT (`item`.`author-link` IN ('https://%s', 'http://%s'))
AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
AND `item`.`parent` IN (SELECT `iid` FROM `thread` WHERE `uid` = %d AND `mention` AND !`ignored`)
$sql_extra
AND `item`.`id`>%d
ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
intval(api_user()),
dbesc(ACTIVITY_POST),
dbesc(protect_sprintf($myurl)),
dbesc(protect_sprintf($myurl)),
intval(api_user()),
intval($since_id),
intval($start),
intval($count)
);
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$ret = api_format_items($r, $user_info, false, $type);
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
$data = ['status' => $ret];
switch ($type) {
@ -2391,46 +2226,31 @@ function api_statuses_user_timeline($type)
}
$start = ($page - 1) * $count;
$sql_extra = '';
$condition = ["`uid` = ? AND `verb` = ? AND `item`.`id` > ? AND `item`.`contact-id` = ?",
api_user(), ACTIVITY_POST, $since_id, $user_info['cid']];
if ($user_info['self'] == 1) {
$sql_extra .= " AND `item`.`wall` = 1 ";
$condition[0] .= ' AND `item`.`wall` ';
}
if ($exclude_replies > 0) {
$sql_extra .= ' AND `item`.`parent` = `item`.`id`';
$condition[0] .= ' AND `item`.`parent` = `item`.`id`';
}
if ($conversation_id > 0) {
$sql_extra .= ' AND `item`.`parent` = ' . intval($conversation_id);
$condition[0] .= " AND `item`.`parent` = ?";
$condition[] = $conversation_id;
}
if ($max_id > 0) {
$sql_extra .= ' AND `item`.`id` <= ' . intval($max_id);
$condition[0] .= " AND `item`.`id` <= ?";
$condition[] = $max_id;
}
$r = q(
"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`,
`contact`.`id` AS `cid`
FROM `item` FORCE INDEX (`uid_contactid_id`)
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
WHERE `item`.`uid` = %d AND `verb` = '%s'
AND `item`.`contact-id` = %d
AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
$sql_extra
AND `item`.`id` > %d
ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
intval(api_user()),
dbesc(ACTIVITY_POST),
intval($user_info['cid']),
intval($since_id),
intval($start),
intval($count)
);
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$ret = api_format_items($r, $user_info, true, $type);
$ret = api_format_items(dba::inArray($statuses), $user_info, true, $type);
$data = ['status' => $ret];
switch ($type) {
@ -2480,24 +2300,24 @@ function api_favorites_create_destroy($type)
$itemid = intval($_REQUEST['id']);
}
$item = q("SELECT * FROM `item` WHERE `id`=%d AND `uid`=%d LIMIT 1", $itemid, api_user());
$item = Item::selectFirst(api_user(), [], ['id' => $itemid, 'uid' => api_user()]);
if (!DBM::is_result($item) || count($item) == 0) {
if (!DBM::is_result($item)) {
throw new BadRequestException("Invalid item.");
}
switch ($action) {
case "create":
$item[0]['starred'] = 1;
$item['starred'] = 1;
break;
case "destroy":
$item[0]['starred'] = 0;
$item['starred'] = 0;
break;
default:
throw new BadRequestException("Invalid action ".$action);
}
$r = Item::update(['starred' => $item[0]['starred']], ['id' => $itemid]);
$r = Item::update(['starred' => $item['starred']], ['id' => $itemid]);
if ($r === false) {
throw new InternalServerErrorException("DB error");
@ -2505,7 +2325,7 @@ function api_favorites_create_destroy($type)
$user_info = api_get_user($a);
$rets = api_format_items($item, $user_info, false, $type);
$rets = api_format_items([$item], $user_info, false, $type);
$ret = $rets[0];
$data = ['status' => $ret];
@ -2549,8 +2369,6 @@ function api_favorites($type)
if ($user_info['self'] == 0) {
$ret = [];
} else {
$sql_extra = "";
// params
$since_id = (x($_REQUEST, 'since_id') ? $_REQUEST['since_id'] : 0);
$max_id = (x($_REQUEST, 'max_id') ? $_REQUEST['max_id'] : 0);
@ -2562,31 +2380,19 @@ function api_favorites($type)
$start = $page*$count;
$condition = ["`uid` = ? AND `verb` = ? AND `id` > ? AND `starred`",
api_user(), ACTIVITY_POST, $since_id];
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
if ($max_id > 0) {
$sql_extra .= ' AND `item`.`id` <= ' . intval($max_id);
$condition[0] .= " AND `item`.`id` <= ?";
$condition[] = $max_id;
}
$r = q(
"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`,
`contact`.`id` AS `cid`
FROM `item`, `contact`
WHERE `item`.`uid` = %d
AND `item`.`visible` = 1 AND `item`.`moderated` = 0 AND `item`.`deleted` = 0
AND `item`.`starred` = 1
AND `contact`.`id` = `item`.`contact-id`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
$sql_extra
AND `item`.`id`>%d
ORDER BY `item`.`id` DESC LIMIT %d ,%d ",
intval(api_user()),
intval($since_id),
intval($start),
intval($count)
);
$statuses = Item::select(api_user(), [], $condition, $params);
$ret = api_format_items($r, $user_info, false, $type);
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
}
$data = ['status' => $ret];
@ -2732,7 +2538,7 @@ function api_convert_item($item)
*
* @param string $body
*
* @return array|false
* @return array
*/
function api_get_attachments(&$body)
{
@ -2743,7 +2549,7 @@ function api_get_attachments(&$body)
$ret = preg_match_all("/\[img\]([$URLSearchString]*)\[\/img\]/ism", $text, $images);
if (!$ret) {
return false;
return [];
}
$attachments = [];
@ -3001,8 +2807,8 @@ function api_format_items_activities(&$item, $type = "json")
];
$items = q(
'SELECT * FROM item
WHERE uid=%d AND `thr-parent`="%s" AND visible AND NOT deleted',
'SELECT * FROM `item`
WHERE `uid` = %d AND `thr-parent` = "%s" AND `visible` AND NOT `deleted`',
intval($item['uid']),
dbesc($item['uri'])
);
@ -3012,7 +2818,7 @@ function api_format_items_activities(&$item, $type = "json")
//builtin_activity_puller($i, $activities);
// get user data and add it to the array of the activity
$user = api_get_user($a, $i['author-link']);
$user = api_get_user($a, $i['author-id']);
switch ($i['verb']) {
case ACTIVITY_LIKE:
$activities['like'][] = $user;
@ -3168,26 +2974,18 @@ function api_format_items($r, $user_info, $filter_user = false, $type = "json")
$status["entities"] = $converted["entities"];
}
if (($item['item_network'] != "") && ($status["source"] == 'web')) {
$status["source"] = ContactSelector::networkToName($item['item_network'], $user_info['url']);
} elseif (($item['item_network'] != "") && (ContactSelector::networkToName($item['item_network'], $user_info['url']) != $status["source"])) {
$status["source"] = trim($status["source"].' ('.ContactSelector::networkToName($item['item_network'], $user_info['url']).')');
if ($status["source"] == 'web') {
$status["source"] = ContactSelector::networkToName($item['network'], $user_info['url']);
} elseif (ContactSelector::networkToName($item['network'], $user_info['url']) != $status["source"]) {
$status["source"] = trim($status["source"].' ('.ContactSelector::networkToName($item['network'], $user_info['url']).')');
}
// Retweets are only valid for top postings
// It doesn't work reliable with the link if its a feed
//$IsRetweet = ($item['owner-link'] != $item['author-link']);
//if ($IsRetweet)
// $IsRetweet = (($item['owner-name'] != $item['author-name']) || ($item['owner-avatar'] != $item['author-avatar']));
if ($item["id"] == $item["parent"]) {
$retweeted_item = api_share_as_retweet($item);
if ($retweeted_item !== false) {
$retweeted_status = $status;
try {
$retweeted_status["user"] = api_get_user($a, $retweeted_item["author-link"]);
$retweeted_status["user"] = api_get_user($a, $retweeted_item["author-id"]);
} catch (BadRequestException $e) {
// user not found. should be found?
/// @todo check if the user should be always found
@ -3384,37 +3182,23 @@ function api_lists_statuses($type)
$start = $page * $count;
$sql_extra = '';
$condition = ["`uid` = ? AND `verb` = ? AND `id` > ? AND `group_member`.`gid` = ?",
api_user(), ACTIVITY_POST, $since_id, $_REQUEST['list_id']];
if ($max_id > 0) {
$sql_extra .= ' AND `item`.`id` <= ' . intval($max_id);
$condition[0] .= " AND `item`.`id` <= ?";
$condition[] = $max_id;
}
if ($exclude_replies > 0) {
$sql_extra .= ' AND `item`.`parent` = `item`.`id`';
$condition[0] .= ' AND `item`.`parent` = `item`.`id`';
}
if ($conversation_id > 0) {
$sql_extra .= ' AND `item`.`parent` = ' . intval($conversation_id);
$condition[0] .= " AND `item`.`parent` = ?";
$condition[] = $conversation_id;
}
$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`,
`contact`.`id` AS `cid`, `group_member`.`gid`
FROM `item`
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` = ? AND `verb` = ?
AND `item`.`visible` AND NOT `item`.`moderated` AND NOT `item`.`deleted`
$sql_extra
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']
);
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$items = api_format_items(dba::inArray($statuses), $user_info, false, $type);
@ -4148,7 +3932,7 @@ function api_fr_photoalbum_delete($type)
if (!DBM::is_result($photo_item)) {
throw new InternalServerErrorException("problem with deleting items occured");
}
Item::deleteById($photo_item[0]['id']);
Item::deleteForUser(['id' => $photo_item[0]['id']], api_user());
}
// now let's delete all photos from the album
@ -4395,7 +4179,6 @@ function api_fr_photo_create_update($type)
throw new InternalServerErrorException("unknown error - this error on uploading or updating a photo should never happen");
}
/**
* @brief delete a single photo from the database through api
*
@ -4441,7 +4224,7 @@ function api_fr_photo_delete($type)
}
// 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)
Item::deleteById($photo_item[0]['id']);
Item::deleteForUser(['id' => $photo_item[0]['id']], api_user());
$answer = ['result' => 'deleted', 'message' => 'photo with id `' . $photo_id . '` has been deleted from server.'];
return api_format_data("photo_delete", $type, ['$result' => $answer]);
@ -4534,6 +4317,7 @@ function api_account_update_profile_image($type)
} else {
throw new InternalServerErrorException('Unsupported filetype');
}
// change specified profile or all profiles to the new resource-id
if ($is_default_profile) {
$condition = ["`profile` AND `resource-id` != ? AND `uid` = ?", $data['photo']['id'], api_user()];
@ -4547,7 +4331,6 @@ function api_account_update_profile_image($type)
Contact::updateSelfFromUserID(api_user(), true);
// Update global directory in background
//$user = api_get_user(get_app());
$url = System::baseUrl() . '/profile/' . get_app()->user['nickname'];
if ($url && strlen(Config::get('system', 'directory'))) {
Worker::add(PRIORITY_LOW, "Directory", $url);
@ -4937,24 +4720,13 @@ function prepare_photo_data($type, $scale, $photo_id)
$data['photo']['friendica_activities'] = api_format_items_activities($item[0], $type);
// retrieve comments on photo
$r = q(
"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`,
`contact`.`id` AS `cid`
FROM `item`
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND `contact`.`uid` = `item`.`uid`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
WHERE `item`.`parent` = %d AND `item`.`visible`
AND NOT `item`.`moderated` AND NOT `item`.`deleted`
AND `item`.`uid` = %d AND (`item`.`verb`='%s' OR `type`='photo')",
intval($item[0]['parent']),
intval(api_user()),
dbesc(ACTIVITY_POST)
);
$condition = ["`parent` = ? AND `uid` = ? AND (`verb` = ? OR `type`='photo')",
$item[0]['parent'], api_user(), ACTIVITY_POST];
$statuses = Item::select(api_user(), [], $condition);
// prepare output of comments
$commentData = api_format_items($r, $user_info, false, $type);
$commentData = api_format_items(dba::inArray($statuses), $user_info, false, $type);
$comments = [];
if ($type == "xml") {
$k = 0;
@ -5255,7 +5027,7 @@ function api_in_reply_to($item)
$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
"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'])
@ -5289,27 +5061,27 @@ function api_in_reply_to($item)
/**
*
* @param string $Text
* @param string $text
*
* @return string
*/
function api_clean_plain_items($Text)
function api_clean_plain_items($text)
{
$include_entities = strtolower(x($_REQUEST, 'include_entities') ? $_REQUEST['include_entities'] : "false");
$Text = BBCode::cleanPictureLinks($Text);
$text = BBCode::cleanPictureLinks($text);
$URLSearchString = "^\[\]";
$Text = preg_replace("/([!#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $Text);
$text = preg_replace("/([!#@])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '$1$3', $text);
if ($include_entities == "true") {
$Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url=$1]$1[/url]', $Text);
$text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url=$1]$1[/url]', $text);
}
// Simplify "attachment" element
$Text = api_clean_attachments($Text);
$text = api_clean_attachments($text);
return($Text);
return $text;
}
/**
@ -5944,14 +5716,10 @@ function api_friendica_notification_seen($type)
$nm->setSeen($note);
if ($note['otype']=='item') {
// would be really better with an ItemsManager and $im->getByID() :-P
$r = q(
"SELECT * FROM `item` WHERE `id`=%d AND `uid`=%d",
intval($note['iid']),
intval(local_user())
);
if ($r!==false) {
$item = Item::selectFirst(api_user(), [], ['id' => $note['iid'], 'uid' => api_user()]);
if (DBM::is_result($$item)) {
// we found the item, return it to the user
$ret = api_format_items($r, $user_info, false, $type);
$ret = api_format_items([$item], $user_info, false, $type);
$data = ['status' => $ret];
return api_format_data("status", $type, $data);
}

View file

@ -15,6 +15,7 @@ use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Profile;
use Friendica\Model\Item;
use Friendica\Object\Post;
use Friendica\Object\Thread;
use Friendica\Util\DateTimeFormat;
@ -116,7 +117,7 @@ function localize_item(&$item) {
$item['body'] = item_redir_and_replace_images($extracted['body'], $extracted['images'], $item['contact-id']);
}
/// @Separted ???
/// @TODO Separted ???
$xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">";
if (activity_match($item['verb'], ACTIVITY_LIKE)
|| activity_match($item['verb'], ACTIVITY_DISLIKE)
@ -162,22 +163,19 @@ function localize_item(&$item) {
if (activity_match($item['verb'], ACTIVITY_LIKE)) {
$bodyverb = L10n::t('%1$s likes %2$s\'s %3$s');
}
elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
} elseif (activity_match($item['verb'], ACTIVITY_DISLIKE)) {
$bodyverb = L10n::t('%1$s doesn\'t like %2$s\'s %3$s');
}
elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
} elseif (activity_match($item['verb'], ACTIVITY_ATTEND)) {
$bodyverb = L10n::t('%1$s attends %2$s\'s %3$s');
}
elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
} elseif (activity_match($item['verb'], ACTIVITY_ATTENDNO)) {
$bodyverb = L10n::t('%1$s doesn\'t attend %2$s\'s %3$s');
}
elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
} elseif (activity_match($item['verb'], ACTIVITY_ATTENDMAYBE)) {
$bodyverb = L10n::t('%1$s attends maybe %2$s\'s %3$s');
}
$item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
$item['body'] = sprintf($bodyverb, $author, $objauthor, $plink);
}
if (activity_match($item['verb'], ACTIVITY_FRIEND)) {
if ($item['object-type']=="" || $item['object-type']!== ACTIVITY_OBJ_PERSON) return;
@ -200,10 +198,10 @@ function localize_item(&$item) {
}
}
$A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
$A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
if ($Bphoto != "") {
$Bphoto = '[url=' . Profile::zrl($Blink) . '][img]' . $Bphoto . '[/img][/url]';
$Bphoto = '[url=' . Contact::magicLink($Blink) . '][img]' . $Bphoto . '[/img][/url]';
}
$item['body'] = L10n::t('%1$s is now friends with %2$s', $A, $B)."\n\n\n".$Bphoto;
@ -237,10 +235,10 @@ function localize_item(&$item) {
}
}
$A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
$A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
if ($Bphoto != "") {
$Bphoto = '[url=' . Profile::zrl($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
$Bphoto = '[url=' . Contact::magicLink($Blink) . '][img=80x80]' . $Bphoto . '[/img][/url]';
}
/*
@ -272,8 +270,8 @@ function localize_item(&$item) {
$obj = $r[0];
$author = '[url=' . Profile::zrl($item['author-link']) . ']' . $item['author-name'] . '[/url]';
$objauthor = '[url=' . Profile::zrl($obj['author-link']) . ']' . $obj['author-name'] . '[/url]';
$author = '[url=' . Contact::magicLinkById($item['author-id']) . ']' . $item['author-name'] . '[/url]';
$objauthor = '[url=' . Contact::magicLinkById($obj['author-id']) . ']' . $obj['author-name'] . '[/url]';
switch ($obj['verb']) {
case ACTIVITY_POST:
@ -304,8 +302,8 @@ function localize_item(&$item) {
$item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag );
}
if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
if (activity_match($item['verb'], ACTIVITY_FAVORITE)) {
if ($item['object-type'] == "") {
return;
}
@ -326,8 +324,8 @@ function localize_item(&$item) {
$target = $r[0];
$Bname = $target['author-name'];
$Blink = $target['author-link'];
$A = '[url=' . Profile::zrl($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . Profile::zrl($Blink) . ']' . $Bname . '[/url]';
$A = '[url=' . Contact::magicLink($Alink) . ']' . $Aname . '[/url]';
$B = '[url=' . Contact::magicLink($Blink) . ']' . $Bname . '[/url]';
$P = '[url=' . $target['plink'] . ']' . L10n::t('post/item') . '[/url]';
$item['body'] = L10n::t('%1$s marked %2$s\'s %3$s as favorite', $A, $B, $P)."\n";
}
@ -337,7 +335,7 @@ function localize_item(&$item) {
if (preg_match_all('/@\[url=(.*?)\]/is', $item['body'], $matches, PREG_SET_ORDER)) {
foreach ($matches as $mtch) {
if (!strpos($mtch[1], 'zrl=')) {
$item['body'] = str_replace($mtch[0], '@[url=' . Profile::zrl($mtch[1]) . ']', $item['body']);
$item['body'] = str_replace($mtch[0], '@[url=' . Contact::magicLink($mtch[1]) . ']', $item['body']);
}
}
}
@ -350,16 +348,7 @@ function localize_item(&$item) {
}
// add sparkle links to appropriate permalinks
$x = stristr($item['plink'],'/display/');
if ($x) {
$sparkle = false;
$y = best_link_url($item, $sparkle);
if (strstr($y, '/redir/')) {
$item['plink'] = $y . '?f=&url=' . $item['plink'];
}
}
$item['plink'] = Contact::magicLinkById($item['author-id'], $item['plink']);
}
/**
@ -394,10 +383,9 @@ function visible_activity($item) {
}
}
if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE) {
if (!($item['self'] && ($item['uid'] == local_user()))) {
return false;
}
// @TODO below if() block can be rewritten to a single line: $isVisible = allConditionsHere;
if (activity_match($item['verb'], ACTIVITY_FOLLOW) && $item['object-type'] === ACTIVITY_OBJ_NOTE && empty($item['self']) && $item['uid'] == local_user()) {
return false;
}
return true;
@ -405,10 +393,12 @@ function visible_activity($item) {
/**
* @brief SQL query for items
*
* @param int $uid user id
*/
function item_query() {
function item_query($uid = 0) {
return "SELECT " . item_fieldlists() . " FROM `item` " .
item_joins() . " WHERE " . item_condition();
item_joins($uid) . " WHERE " . item_condition();
}
/**
@ -429,7 +419,6 @@ These Fields are not added below (yet). They are here to for bug search.
`item`.`inform`,
`item`.`pubmail`,
`item`.`visible`,
`item`.`spam`,
`item`.`bookmark`,
`item`.`unseen`,
`item`.`deleted`,
@ -437,10 +426,12 @@ These Fields are not added below (yet). They are here to for bug search.
`item`.`mention`,
`item`.`global`,
`item`.`shadow`,
`item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
`item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
*/
return "`item`.`author-id`, `item`.`author-link`, `item`.`author-name`, `item`.`author-avatar`,
`item`.`owner-id`, `item`.`owner-link`, `item`.`owner-name`, `item`.`owner-avatar`,
return "`item`.`author-id`,
`item`.`owner-id`,
`item`.`contact-id`, `item`.`uid`, `item`.`id`, `item`.`parent`,
`item`.`uri`, `item`.`thr-parent`, `item`.`parent-uri`, `item`.`content-warning`,
`item`.`commented`, `item`.`created`, `item`.`edited`, `item`.`received`,
@ -452,7 +443,9 @@ These Fields are not added below (yet). They are here to for bug search.
`item`.`allow_cid`, `item`.`allow_gid`, `item`.`deny_cid`, `item`.`deny_gid`,
`item`.`id` AS `item_id`, `item`.`network` AS `item_network`,
`author`.`thumb` AS `author-thumb`, `owner`.`thumb` AS `owner-thumb`,
`author`.`url` AS `author-link`, `author`.`name` AS `author-name`, `author`.`thumb` AS `author-avatar`,
`owner`.`url` AS `owner-link`, `owner`.`name` AS `owner-name`, `owner`.`thumb` AS `owner-avatar`,
`contact`.`url` AS `contact-link`, `contact`.`name` AS `contact-name`, `contact`.`thumb` AS `contact-avatar`,
`contact`.`network`, `contact`.`url`, `contact`.`name`, `contact`.`writable`,
`contact`.`self`, `contact`.`id` AS `cid`, `contact`.`alias`,
@ -467,16 +460,19 @@ These Fields are not added below (yet). They are here to for bug search.
/**
* @brief SQL join for contacts that are needed for displaying items
*
* @param int $uid user id
*/
function item_joins() {
function item_joins($uid = 0) {
return sprintf("STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND NOT `contact`.`blocked`
AND ((NOT `contact`.`readonly` AND NOT `contact`.`pending` AND (`contact`.`rel` IN (%s, %s)))
OR `contact`.`self` OR (`item`.`id` != `item`.`parent`) OR `contact`.`uid` = 0)
INNER JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` AND NOT `author`.`blocked`
INNER JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id` AND NOT `owner`.`blocked`
STRAIGHT_JOIN `contact` AS `author` ON `author`.`id`=`item`.`author-id` AND NOT `author`.`blocked`
STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id`=`item`.`owner-id` AND NOT `owner`.`blocked`
LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d
LEFT JOIN `event` ON `event-id` = `event`.`id`",
CONTACT_IS_SHARING, CONTACT_IS_FRIEND
CONTACT_IS_SHARING, CONTACT_IS_FRIEND, intval($uid)
);
}
@ -484,7 +480,7 @@ function item_joins() {
* @brief SQL condition for items that are needed for displaying items
*/
function item_condition() {
return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated`";
return "`item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) ";
}
/**
@ -497,7 +493,7 @@ function item_condition() {
* that are based on unique features of the calling module.
*
*/
function conversation(App $a, $items, $mode, $update, $preview = false, $order = 'commented') {
function conversation(App $a, $items, $mode, $update, $preview = false, $order = 'commented', $uid = 0) {
require_once 'mod/proxy.php';
$ssl_state = ((local_user()) ? true : false);
@ -521,7 +517,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
$previewing = (($preview) ? ' preview ' : '');
if ($mode === 'network') {
$items = conversation_add_children($items, false, $order);
$items = conversation_add_children($items, false, $order, $uid);
$profile_owner = local_user();
if (!$update) {
/*
@ -540,7 +536,6 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
. ((x($_GET, 'bmark')) ? '&bmark=' . $_GET['bmark'] : '')
. ((x($_GET, 'liked')) ? '&liked=' . $_GET['liked'] : '')
. ((x($_GET, 'conv')) ? '&conv=' . $_GET['conv'] : '')
. ((x($_GET, 'spam')) ? '&spam=' . $_GET['spam'] : '')
. ((x($_GET, 'nets')) ? '&nets=' . $_GET['nets'] : '')
. ((x($_GET, 'cmin')) ? '&cmin=' . $_GET['cmin'] : '')
. ((x($_GET, 'cmax')) ? '&cmax=' . $_GET['cmax'] : '')
@ -582,7 +577,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
. " var profile_page = 1; </script>";
}
} elseif ($mode === 'community') {
$items = conversation_add_children($items, true, $order);
$items = conversation_add_children($items, true, $order, $uid);
$profile_owner = 0;
if (!$update) {
$live_update_div = '<div id="live-community"></div>' . "\r\n"
@ -666,6 +661,13 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
continue;
}
if ($item['network'] == NETWORK_FEED) {
$item['author-avatar'] = $item['contact-avatar'];
$item['author-name'] = $item['contact-name'];
$item['owner-avatar'] = $item['contact-avatar'];
$item['owner-name'] = $item['contact-name'];
}
$profile_name = (strlen($item['author-name']) ? $item['author-name'] : $item['name']);
if ($item['author-link'] && !$item['author-name']) {
$profile_name = $item['author-link'];
@ -673,34 +675,10 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
$tags = \Friendica\Model\Term::populateTagsFromItem($item);
$sp = false;
$profile_link = best_link_url($item, $sp);
if ($profile_link === 'mailbox') {
$profile_link = '';
}
$profile_link = Contact::magicLinkbyId($item['author-id']);
if ($sp) {
if (strpos($profile_link, 'redir/') === 0) {
$sparkle = ' sparkle';
} else {
$profile_link = Profile::zrl($profile_link);
}
if (!x($item, 'author-thumb') || ($item['author-thumb'] == "")) {
$author_contact = Contact::getDetailsByURL($item['author-link'], $profile_owner);
if ($author_contact["thumb"]) {
$item['author-thumb'] = $author_contact["thumb"];
} else {
$item['author-thumb'] = $item['author-avatar'];
}
}
if (!isset($item['owner-thumb']) || ($item['owner-thumb'] == "")) {
$owner_contact = Contact::getDetailsByURL($item['owner-link'], $profile_owner);
if ($owner_contact["thumb"]) {
$item['owner-thumb'] = $owner_contact["thumb"];
} else {
$item['owner-thumb'] = $item['owner-avatar'];
}
}
$locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
@ -757,13 +735,13 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
'guid' => (($preview) ? 'Q0' : $item['guid']),
'network' => $item['item_network'],
'network_name' => ContactSelector::networkToName($item['item_network'], $profile_link),
'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
'profile_url' => $profile_link,
'item_photo_menu' => item_photo_menu($item),
'name' => $profile_name_e,
'sparkle' => $sparkle,
'lock' => $lock,
'thumb' => System::removedBaseUrl(proxy_url($item['author-thumb'], false, PROXY_SIZE_THUMB)),
'thumb' => System::removedBaseUrl(proxy_url($item['author-avatar'], false, PROXY_SIZE_THUMB)),
'title' => $title_e,
'body' => $body_e,
'tags' => $tags_e,
@ -782,7 +760,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
'indent' => '',
'owner_name' => $owner_name_e,
'owner_url' => $owner_url,
'owner_photo' => System::removedBaseUrl(proxy_url($item['owner-thumb'], false, PROXY_SIZE_THUMB)),
'owner_photo' => System::removedBaseUrl(proxy_url($item['owner-avatar'], false, PROXY_SIZE_THUMB)),
'plink' => get_plink($item),
'edpost' => false,
'isstarred' => $isstarred,
@ -885,24 +863,24 @@ function conversation(App $a, $items, $mode, $update, $preview = false, $order =
*
* @return array items with parents and comments
*/
function conversation_add_children($parents, $block_authors, $order) {
function conversation_add_children($parents, $block_authors, $order, $uid) {
$max_comments = Config::get('system', 'max_comments', 100);
$params = ['order' => ['uid', 'commented' => true]];
if ($max_comments > 0) {
$limit = ' LIMIT '.intval($max_comments + 1);
} else {
$limit = '';
$params['limit'] = $max_comments;
}
$items = [];
$block_sql = $block_authors ? "AND NOT `author`.`hidden` AND NOT `author`.`blocked`" : "";
foreach ($parents AS $parent) {
$thread_items = dba::p(item_query()."AND `item`.`parent-uri` = ?
AND `item`.`uid` IN (0, ?) $block_sql
ORDER BY `item`.`uid` ASC, `item`.`commented` DESC" . $limit,
$parent['uri'], local_user());
$condition = ["`item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) ",
$parent['uri'], local_user()];
if ($block_authors) {
$condition[0] .= "AND NOT `author`.`hidden`";
}
$thread_items = Item::select(local_user(), [], $condition, $params);
$comments = dba::inArray($thread_items);
@ -922,48 +900,6 @@ function conversation_add_children($parents, $block_authors, $order) {
return $items;
}
function best_link_url($item, &$sparkle, $url = '') {
$best_url = '';
$sparkle = false;
$clean_url = normalise_link($item['author-link']);
if (local_user()) {
$condition = [
'network' => NETWORK_DFRN,
'uid' => local_user(),
'nurl' => normalise_link($clean_url),
'pending' => false
];
$contact = dba::selectFirst('contact', ['id'], $condition);
if (DBM::is_result($contact)) {
$best_url = 'redir/' . $contact['id'];
$sparkle = true;
if ($url != '') {
$hostname = get_app()->get_hostname();
if (!strstr($url, $hostname)) {
$best_url .= "?url=".$url;
} else {
$best_url = $url;
}
}
}
}
if (!$best_url) {
if ($url != '') {
$best_url = $url;
} elseif (strlen($item['author-link'])) {
$best_url = $item['author-link'];
} else {
$best_url = $item['url'];
}
}
return $best_url;
}
function item_photo_menu($item) {
$sub_link = '';
$poke_link = '';
@ -977,11 +913,8 @@ function item_photo_menu($item) {
$sub_link = 'javascript:dosubthread(' . $item['id'] . '); return false;';
}
$sparkle = false;
$profile_link = best_link_url($item, $sparkle);
if ($profile_link === 'mailbox') {
$profile_link = '';
}
$profile_link = Contact::magicLinkById($item['author-id']);
$sparkle = (strpos($profile_link, 'redir/') === 0);
$cid = 0;
$network = '';
@ -999,7 +932,7 @@ function item_photo_menu($item) {
$photos_link = $profile_link . '?url=photos';
$profile_link = $profile_link . '?url=profile';
} else {
$profile_link = Profile::zrl($profile_link);
$profile_link = Contact::magicLink($profile_link);
}
if ($cid && !$item['self']) {
@ -1087,17 +1020,14 @@ function builtin_activity_puller($item, &$conv_responses) {
}
if (activity_match($item['verb'], $verb) && ($item['id'] != $item['parent'])) {
$url = $item['author-link'];
if (local_user() && (local_user() == $item['uid']) && ($item['network'] === NETWORK_DFRN) && !$item['self'] && link_compare($item['author-link'], $item['url'])) {
$url = 'redir/' . $item['contact-id'];
$url = Contact::MagicLinkbyId($item['author-id']);
if (strpos($url, 'redir/') === 0) {
$sparkle = ' class="sparkle" ';
} else {
$url = Profile::zrl($url);
}
$url = '<a href="'. $url . '"'. $sparkle .'>' . htmlentities($item['author-name']) . '</a>';
if (!$item['thr-parent']) {
if (!x($item, 'thr-parent')) {
$item['thr-parent'] = $item['parent-uri'];
}
@ -1585,19 +1515,17 @@ function sort_thr_commented(array $a, array $b)
return strcmp($b['commented'], $a['commented']);
}
/// @TODO Add type-hint
function render_location_dummy($item) {
if ($item['location'] != "") {
function render_location_dummy(array $item) {
if (x($item, 'location') && !empty($item['location'])) {
return $item['location'];
}
if ($item['coord'] != "") {
if (x($item, 'coord') && !empty($item['coord'])) {
return $item['coord'];
}
}
/// @TODO Add type-hint
function get_responses($conv_responses, $response_verbs, $ob, $item) {
function get_responses(array $conv_responses, array $response_verbs, $ob, array $item) {
$ret = [];
foreach ($response_verbs as $v) {
$ret[$v] = [];

View file

@ -27,7 +27,7 @@ class dba {
private static $relation = [];
public static function connect($serveraddr, $user, $pass, $db) {
if (!is_null(self::$db)) {
if (!is_null(self::$db) && self::connected()) {
return true;
}
@ -54,16 +54,6 @@ echo "1";
return false;
}
if ($a->mode == App::MODE_INSTALL) {
// server has to be a non-empty string that is not 'localhost' and not an IP
if (strlen($server) && ($server !== 'localhost') && filter_var($server, FILTER_VALIDATE_IP) === false) {
if (! dns_get_record($server, DNS_A + DNS_CNAME)) {
self::$error = L10n::t('Cannot locate DNS info for database server \'%s\'', $server);
return false;
}
}
}
if (class_exists('\PDO') && in_array('mysql', PDO::getAvailableDrivers())) {
self::$driver = 'pdo';
$connect = "mysql:host=".$server.";dbname=".$db;
@ -119,6 +109,35 @@ echo "1";
return $ret;
}
/**
* Disconnects the current database connection
*/
public static function disconnect()
{
if (is_null(self::$db)) {
return;
}
switch (self::$driver) {
case 'pdo':
self::$db = null;
break;
case 'mysqli':
self::$db->close();
self::$db = null;
break;
}
}
/**
* Return the database object.
* @return PDO|mysqli
*/
public static function get_db()
{
return self::$db;
}
/**
* @brief Returns the MySQL server version string
*
@ -1184,29 +1203,9 @@ echo "1";
$condition_string = self::buildCondition($condition);
$order_string = '';
if (isset($params['order'])) {
$order_string = " ORDER BY ";
foreach ($params['order'] AS $fields => $order) {
if (!is_int($fields)) {
$order_string .= "`" . $fields . "` " . ($order ? "DESC" : "ASC") . ", ";
} else {
$order_string .= "`" . $order . "`, ";
}
}
$order_string = substr($order_string, 0, -2);
}
$param_string = self::buildParameter($params);
$limit_string = '';
if (isset($params['limit']) && is_int($params['limit'])) {
$limit_string = " LIMIT " . $params['limit'];
}
if (isset($params['limit']) && is_array($params['limit'])) {
$limit_string = " LIMIT " . intval($params['limit'][0]) . ", " . intval($params['limit'][1]);
}
$sql = "SELECT " . $select_fields . " FROM `" . $table . "`" . $condition_string . $order_string . $limit_string;
$sql = "SELECT " . $select_fields . " FROM `" . $table . "`" . $condition_string . $param_string;
$result = self::p($sql, $condition);
@ -1263,14 +1262,14 @@ echo "1";
* @param array $condition
* @return string
*/
private static function buildCondition(array &$condition = [])
public static function buildCondition(array &$condition = [])
{
$condition_string = '';
if (count($condition) > 0) {
reset($condition);
$first_key = key($condition);
if (is_int($first_key)) {
$condition_string = " WHERE ".array_shift($condition);
$condition_string = " WHERE (" . array_shift($condition) . ")";
} else {
$new_values = [];
$condition_string = "";
@ -1287,7 +1286,7 @@ echo "1";
$condition_string .= "`" . $field . "` = ?";
}
}
$condition_string = " WHERE " . $condition_string;
$condition_string = " WHERE (" . $condition_string . ")";
$condition = $new_values;
}
}
@ -1295,6 +1294,39 @@ echo "1";
return $condition_string;
}
/**
* @brief Returns the SQL parameter string built from the provided parameter array
*
* @param array $params
* @return string
*/
public static function buildParameter(array $params = [])
{
$order_string = '';
if (isset($params['order'])) {
$order_string = " ORDER BY ";
foreach ($params['order'] AS $fields => $order) {
if (!is_int($fields)) {
$order_string .= "`" . $fields . "` " . ($order ? "DESC" : "ASC") . ", ";
} else {
$order_string .= "`" . $order . "`, ";
}
}
$order_string = substr($order_string, 0, -2);
}
$limit_string = '';
if (isset($params['limit']) && is_int($params['limit'])) {
$limit_string = " LIMIT " . $params['limit'];
}
if (isset($params['limit']) && is_array($params['limit'])) {
$limit_string = " LIMIT " . intval($params['limit'][0]) . ", " . intval($params['limit'][1]);
}
return $order_string.$limit_string;
}
/**
* @brief Fills an array with data from a query
*

View file

@ -11,6 +11,7 @@ use Friendica\Core\System;
use Friendica\Database\DBM;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Emailer;
use Friendica\Model\Item;
/**
* @brief Creates a notification entry and possibly sends a mail
@ -129,7 +130,7 @@ function notification($params)
$item = null;
if ($params['otype'] === 'item' && $parent_id) {
$item = dba::selectFirst('item', [], ['id' => $parent_id]);
$item = Item::selectFirst($params['uid'], [], ['id' => $parent_id]);
}
$item_post_type = item_post_type($item);
@ -152,7 +153,7 @@ function notification($params)
}
// "your post"
if (DBM::is_result($item) && $item['owner-name'] == $item['author-name'] && $item['wall']) {
if (DBM::is_result($item) && $item['owner-id'] == $item['author-id'] && $item['wall']) {
$dest_str = L10n::t('%1$s commented on [url=%2$s]your %3$s[/url]',
'[url='.$params['source_link'].']'.$params['source_name'].'[/url]',
$itemlink,
@ -739,7 +740,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
// Only act if it is a "real" post
// We need the additional check for the "local_profile" because of mixed situations on connector networks
$item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-name`, `author-link`, `author-avatar`, `guid`,
$item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-id`, `guid`,
`parent-uri`, `uri`, `contact-id`
FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND
NOT (`author-link` IN ($profile_list)) LIMIT 1",
@ -747,6 +748,8 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
if (!$item)
return false;
$author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item[0]['author-id']]);
// Generate the notification array
$params = [];
$params["uid"] = $uid;
@ -758,9 +761,9 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
$params["parent"] = $item[0]["parent"];
$params["link"] = System::baseUrl().'/display/'.urlencode($item[0]["guid"]);
$params["otype"] = 'item';
$params["source_name"] = $item[0]["author-name"];
$params["source_link"] = $item[0]["author-link"];
$params["source_photo"] = $item[0]["author-avatar"];
$params["source_name"] = $author["name"];
$params["source_link"] = $author["url"];
$params["source_photo"] = $author["thumb"];
if ($item[0]["parent-uri"] === $item[0]["uri"]) {
// Send a notification for every new post?

View file

@ -274,6 +274,7 @@ function consume_feed($xml, $importer, $contact, &$hub, $datedir = 0, $pass = 0)
function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') {
$a = get_app();
$r = null;
if (is_array($importer)) {
$r = q("SELECT `nickname` FROM `user` WHERE `uid` = %d LIMIT 1",
@ -321,7 +322,7 @@ function drop_items($items) {
if (count($items)) {
foreach ($items as $item) {
$owner = Item::deleteById($item);
$owner = Item::deleteForUser(['id' => $item], local_user());
if ($owner && !$uid)
$uid = $owner;
}
@ -393,7 +394,7 @@ function drop_item($id) {
}
// delete the item
Item::deleteById($item['id']);
Item::deleteForUser(['id' => $item['id']], local_user());
goaway(System::baseUrl() . '/' . $_SESSION['return_url']);
//NOTREACHED

View file

@ -254,6 +254,7 @@ function can_write_wall($owner)
return false;
}
/// @TODO $groups should be array
function permissions_sql($owner_id, $remote_verified = false, $groups = null)
{
$local_user = local_user();
@ -275,6 +276,13 @@ function permissions_sql($owner_id, $remote_verified = false, $groups = null)
*/
if ($local_user && $local_user == $owner_id) {
$sql = '';
/**
* Authenticated visitor. Unless pre-verified,
* check that the contact belongs to this $owner_id
* and load the groups the visitor belongs to.
* If pre-verified, the caller is expected to have already
* done this and passed the groups into this function.
*/
} elseif ($remote_user) {
/*
* Authenticated visitor. Unless pre-verified,
@ -298,9 +306,10 @@ function permissions_sql($owner_id, $remote_verified = false, $groups = null)
if ($remote_verified) {
$gs = '<<>>'; // should be impossible to match
if (is_array($groups) && count($groups)) {
foreach ($groups as $g)
if (is_array($groups)) {
foreach ($groups as $g) {
$gs .= '|<' . intval($g) . '>';
}
}
$sql = sprintf(

View file

@ -152,7 +152,7 @@ function autoname($len) {
'nd','ng','nk','nt','rn','rp','rt'];
$noend = ['bl', 'br', 'cl','cr','dr','fl','fr','gl','gr',
'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh'];
'kh', 'kl','kr','mn','pl','pr','rh','tr','qu','wh','q'];
$start = mt_rand(0,2);
if ($start == 0) {
@ -178,14 +178,13 @@ function autoname($len) {
$word = substr($word,0,$len);
foreach ($noend as $noe) {
if ((strlen($word) > 2) && (substr($word, -2) == $noe)) {
$word = substr($word, 0, -1);
$noelen = strlen($noe);
if ((strlen($word) > $noelen) && (substr($word, -$noelen) == $noe)) {
$word = autoname($len);
break;
}
}
if (substr($word, -1) == 'q') {
$word = substr($word, 0, -1);
}
return $word;
}
@ -453,7 +452,7 @@ function perms2str($p) {
if (is_array($p)) {
$tmp = $p;
} else {
$tmp = explode(',',$p);
$tmp = explode(',', $p);
}
if (is_array($tmp)) {
@ -962,13 +961,9 @@ function micropro($contact, $redirect = false, $class = '', $textmode = false) {
$redir = false;
if ($redirect) {
$redirect_url = 'redir/' . $contact['id'];
if (local_user() && ($contact['uid'] == local_user()) && ($contact['network'] === NETWORK_DFRN)) {
$redir = true;
$url = $redirect_url;
$url = Contact::magicLink($contact['url']);
if (strpos($url, 'redir/') === 0) {
$sparkle = ' sparkle';
} else {
$url = Profile::zrl($url);
}
}
@ -1301,11 +1296,7 @@ function prepare_body(array &$item, $attach = false, $is_preview = false)
foreach ($matches as $mtch) {
$mime = $mtch[3];
if ((local_user() == $item['uid']) && ($item['contact-id'] != $a->contact['id']) && ($item['network'] == NETWORK_DFRN)) {
$the_url = 'redir/' . $item['contact-id'] . '?f=1&url=' . $mtch[1];
} else {
$the_url = $mtch[1];
}
$the_url = Contact::magicLinkById($item['author-id'], $mtch[1]);
if (strpos($mime, 'video') !== false) {
if (!$vhead) {
@ -1661,10 +1652,11 @@ function bb_translate_video($s) {
$r = preg_match_all("/\[video\](.*?)\[\/video\]/ism",$s,$matches,PREG_SET_ORDER);
if ($r) {
foreach ($matches as $mtch) {
if ((stristr($mtch[1],'youtube')) || (stristr($mtch[1],'youtu.be')))
$s = str_replace($mtch[0],'[youtube]' . $mtch[1] . '[/youtube]',$s);
elseif (stristr($mtch[1],'vimeo'))
$s = str_replace($mtch[0],'[vimeo]' . $mtch[1] . '[/vimeo]',$s);
if ((stristr($mtch[1], 'youtube')) || (stristr($mtch[1], 'youtu.be'))) {
$s = str_replace($mtch[0], '[youtube]' . $mtch[1] . '[/youtube]', $s);
} elseif (stristr($mtch[1], 'vimeo')) {
$s = str_replace($mtch[0], '[vimeo]' . $mtch[1] . '[/vimeo]', $s);
}
}
}
return $s;
@ -1782,7 +1774,7 @@ function file_tag_file_query($table,$s,$type = 'file') {
}
// ex. given music,video return <music><video> or [music][video]
function file_tag_list_to_file($list,$type = 'file') {
function file_tag_list_to_file($list, $type = 'file') {
$tag_list = '';
if (strlen($list)) {
$list_array = explode(",",$list);
@ -1804,7 +1796,7 @@ function file_tag_list_to_file($list,$type = 'file') {
}
// ex. given <music><video>[friends], return music,video or friends
function file_tag_file_to_list($file,$type = 'file') {
function file_tag_file_to_list($file, $type = 'file') {
$matches = false;
$list = '';
if ($type == 'file') {
@ -1830,8 +1822,7 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
if (!intval($uid)) {
return false;
}
if ($file_old == $file_new) {
} elseif ($file_old == $file_new) {
return true;
}
@ -1854,8 +1845,9 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
$check_new_tags = explode(",",file_tag_file_to_list($file_new,$type));
foreach ($check_new_tags as $tag) {
if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket))
if (! stristr($saved,$lbracket . file_tag_encode($tag) . $rbracket)) {
$new_tags[] = $tag;
}
}
$filetags_updated .= file_tag_list_to_file(implode(",",$new_tags),$type);
@ -1865,8 +1857,9 @@ function file_tag_update_pconfig($uid, $file_old, $file_new, $type = 'file') {
$check_deleted_tags = explode(",",file_tag_file_to_list($file_old,$type));
foreach ($check_deleted_tags as $tag) {
if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket))
if (! stristr($file_new,$lbracket . file_tag_encode($tag) . $rbracket)) {
$deleted_tags[] = $tag;
}
}
foreach ($deleted_tags as $key => $tag) {
@ -1980,17 +1973,22 @@ function protect_sprintf($s) {
return str_replace('%', '%%', $s);
}
/// @TODO Rewrite this
function is_a_date_arg($s) {
$i = intval($s);
if ($i > 1900) {
$y = date('Y');
if ($i <= $y + 1 && strpos($s, '-') == 4) {
$m = intval(substr($s,5));
if ($m > 0 && $m <= 12)
$m = intval(substr($s, 5));
if ($m > 0 && $m <= 12) {
return true;
}
}
}
return false;
}
@ -2008,6 +2006,7 @@ function deindent($text, $chr = "[\t ]", $count = NULL) {
preg_match("|^" . $chr . "*|", $lines[$k], $m);
$count = strlen($m[0]);
}
for ($k = 0; $k < count($lines); $k++) {
$lines[$k] = preg_replace("|^" . $chr . "{" . $count . "}|", "", $lines[$k]);
}