More item abstractions for DFRN and Diaspora
This commit is contained in:
parent
6f9ec690aa
commit
1aec8f620d
3 changed files with 108 additions and 141 deletions
|
@ -162,9 +162,6 @@ class Item extends BaseObject
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
These Fields are not added below. They are here to for bug search.
|
These Fields are not added below. They are here to for bug search.
|
||||||
'type', 'extid', 'changed', 'moderated', 'target-type', 'target', 'resource-id',
|
|
||||||
'tag', 'inform', 'pubmail', 'visible', 'bookmark', 'unseen', 'deleted',
|
|
||||||
'forum_mode', 'mention', 'global', 'shadow',
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$item_fields = ['author-id', 'owner-id', 'contact-id', 'uid', 'id', 'parent',
|
$item_fields = ['author-id', 'owner-id', 'contact-id', 'uid', 'id', 'parent',
|
||||||
|
@ -172,13 +169,24 @@ class Item extends BaseObject
|
||||||
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
|
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
|
||||||
'guid', 'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'event-id',
|
'guid', 'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'event-id',
|
||||||
'location', 'coord', 'app', 'attach', 'rendered-hash', 'rendered-html', 'object',
|
'location', 'coord', 'app', 'attach', 'rendered-hash', 'rendered-html', 'object',
|
||||||
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'unseen',
|
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
|
||||||
'id' => 'item_id', 'network' => 'item_network'];
|
'id' => 'item_id', 'network' => 'item_network'];
|
||||||
|
|
||||||
|
// The additional fields aren't needed to be selected by default.
|
||||||
|
// We need them to select the correct tables. To see the difference we split the arrays
|
||||||
|
if (!empty($selected)) {
|
||||||
|
$additional_item_fields = ['type', 'extid', 'changed', 'moderated', 'target-type', 'target',
|
||||||
|
'resource-id', 'tag', 'inform', 'pubmail', 'visible', 'bookmark', 'unseen', 'deleted',
|
||||||
|
'forum_mode', 'mention', 'global', 'shadow'];
|
||||||
|
|
||||||
|
$item_fields = array_merge($item_fields, $additional_item_fields);
|
||||||
|
}
|
||||||
|
|
||||||
$author_fields = ['url' => 'author-link', 'name' => 'author-name', 'thumb' => 'author-avatar'];
|
$author_fields = ['url' => 'author-link', 'name' => 'author-name', 'thumb' => 'author-avatar'];
|
||||||
$owner_fields = ['url' => 'owner-link', 'name' => 'owner-name', 'thumb' => 'owner-avatar'];
|
$owner_fields = ['url' => 'owner-link', 'name' => 'owner-name', 'thumb' => 'owner-avatar'];
|
||||||
$contact_fields = ['url' => 'contact-link', 'name' => 'contact-name', 'thumb' => 'contact-avatar',
|
$contact_fields = ['url' => 'contact-link', 'name' => 'contact-name', 'thumb' => 'contact-avatar',
|
||||||
'network', 'url', 'name', 'writable', 'self', 'id' => 'cid', 'alias'];
|
'network', 'url', 'name', 'writable', 'self', 'id' => 'cid', 'alias',
|
||||||
|
'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id'];
|
||||||
|
|
||||||
$event_fields = ['created' => 'event-created', 'edited' => 'event-edited',
|
$event_fields = ['created' => 'event-created', 'edited' => 'event-edited',
|
||||||
'start' => 'event-start','finish' => 'event-finish',
|
'start' => 'event-start','finish' => 'event-finish',
|
||||||
|
@ -193,6 +201,7 @@ class Item extends BaseObject
|
||||||
if (!empty($selected)) {
|
if (!empty($selected)) {
|
||||||
$fields['parent-item'] = ['guid' => 'parent-guid'];
|
$fields['parent-item'] = ['guid' => 'parent-guid'];
|
||||||
$fields['parent-item-author'] = ['url' => 'parent-author-link', 'name' => 'parent-author-name'];
|
$fields['parent-item-author'] = ['url' => 'parent-author-link', 'name' => 'parent-author-name'];
|
||||||
|
$fields['sign'] = ['signed_text', 'signature', 'signer'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
|
@ -257,6 +266,10 @@ class Item extends BaseObject
|
||||||
$joins .= " LEFT JOIN `event` ON `event-id` = `event`.`id`";
|
$joins .= " LEFT JOIN `event` ON `event-id` = `event`.`id`";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (strpos($sql_commands, "`sign`.") !== false) {
|
||||||
|
$joins .= " LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`";
|
||||||
|
}
|
||||||
|
|
||||||
if ((strpos($sql_commands, "`parent-item`.") !== false) || (strpos($sql_commands, "`parent-author`.") !== false)) {
|
if ((strpos($sql_commands, "`parent-item`.") !== false) || (strpos($sql_commands, "`parent-author`.") !== false)) {
|
||||||
$joins .= " STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent`";
|
$joins .= " STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent`";
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,17 +228,10 @@ class DFRN
|
||||||
$check_date = DateTimeFormat::utc($last_update);
|
$check_date = DateTimeFormat::utc($last_update);
|
||||||
|
|
||||||
$r = q(
|
$r = q(
|
||||||
"SELECT `item`.*, `item`.`id` AS `item_id`,
|
"SELECT `item`.`id`
|
||||||
`contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`,
|
|
||||||
`contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
|
|
||||||
`contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
|
|
||||||
`sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
|
|
||||||
FROM `item` USE INDEX (`uid_wall_changed`) $sql_post_table
|
FROM `item` USE INDEX (`uid_wall_changed`) $sql_post_table
|
||||||
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
||||||
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
|
WHERE `item`.`uid` = %d AND `item`.`wall` AND `item`.`changed` > '%s'
|
||||||
LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
|
|
||||||
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`moderated` AND `item`.`parent` != 0
|
|
||||||
AND `item`.`wall` AND `item`.`changed` > '%s'
|
|
||||||
$sql_extra
|
$sql_extra
|
||||||
ORDER BY `item`.`parent` ".$sort.", `item`.`created` ASC LIMIT 0, 300",
|
ORDER BY `item`.`parent` ".$sort.", `item`.`created` ASC LIMIT 0, 300",
|
||||||
intval($owner_id),
|
intval($owner_id),
|
||||||
|
@ -246,13 +239,26 @@ class DFRN
|
||||||
dbesc($sort)
|
dbesc($sort)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$ids = [];
|
||||||
|
foreach ($r as $item) {
|
||||||
|
$ids[] = $item['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$condition = ['id' => $ids];
|
||||||
|
$fields = ['author-id', 'uid', 'id', 'parent', 'uri', 'thr-parent',
|
||||||
|
'parent-uri', 'created', 'edited', 'verb', 'object-type',
|
||||||
|
'guid', 'private', 'title', 'body', 'location', 'coord', 'app',
|
||||||
|
'attach', 'object', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
|
||||||
|
'extid', 'target', 'tag', 'bookmark', 'deleted',
|
||||||
|
'author-link', 'owner-link', 'signed_text', 'signature', 'signer'];
|
||||||
|
$ret = Item::select($owner_id, $fields, $condition);
|
||||||
|
$items = dba::inArray($ret);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Will check further below if this actually returned results.
|
* Will check further below if this actually returned results.
|
||||||
* We will provide an empty feed if that is the case.
|
* We will provide an empty feed if that is the case.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$items = $r;
|
|
||||||
|
|
||||||
$doc = new DOMDocument('1.0', 'utf-8');
|
$doc = new DOMDocument('1.0', 'utf-8');
|
||||||
$doc->formatOutput = true;
|
$doc->formatOutput = true;
|
||||||
|
|
||||||
|
@ -321,33 +327,24 @@ class DFRN
|
||||||
public static function itemFeed($item_id, $conversation = false)
|
public static function itemFeed($item_id, $conversation = false)
|
||||||
{
|
{
|
||||||
if ($conversation) {
|
if ($conversation) {
|
||||||
$condition = '`item`.`parent`';
|
$condition = ['parent' => $item_id];
|
||||||
} else {
|
} else {
|
||||||
$condition = '`item`.`id`';
|
$condition = ['id' => $item_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q(
|
$fields = ['author-id', 'uid', 'id', 'parent', 'uri', 'thr-parent',
|
||||||
"SELECT `item`.*, `item`.`id` AS `item_id`,
|
'parent-uri', 'created', 'edited', 'verb', 'object-type',
|
||||||
`contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`,
|
'guid', 'private', 'title', 'body', 'location', 'coord', 'app',
|
||||||
`contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
|
'attach', 'object', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
|
||||||
`contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
|
'extid', 'target', 'tag', 'bookmark', 'deleted',
|
||||||
`sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
|
'author-link', 'owner-link', 'signed_text', 'signature', 'signer'];
|
||||||
FROM `item`
|
$ret = Item::select(0, $fields, $condition);
|
||||||
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
$items = dba::inArray($ret);
|
||||||
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
|
if (!DBM::is_result($items)) {
|
||||||
LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
|
|
||||||
WHERE %s = %d AND `item`.`visible` AND NOT `item`.`moderated` AND `item`.`parent` != 0
|
|
||||||
AND NOT `item`.`private`",
|
|
||||||
$condition,
|
|
||||||
intval($item_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!DBM::is_result($r)) {
|
|
||||||
killme();
|
killme();
|
||||||
}
|
}
|
||||||
|
|
||||||
$items = $r;
|
$item = $items[0];
|
||||||
$item = $r[0];
|
|
||||||
|
|
||||||
if ($item['uid'] != 0) {
|
if ($item['uid'] != 0) {
|
||||||
$owner = User::getOwnerDataById($item['uid']);
|
$owner = User::getOwnerDataById($item['uid']);
|
||||||
|
@ -2253,6 +2250,8 @@ class DFRN
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($Blink && link_compare($Blink, System::baseUrl() . "/profile/" . $importer["nickname"])) {
|
if ($Blink && link_compare($Blink, System::baseUrl() . "/profile/" . $importer["nickname"])) {
|
||||||
|
$author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item['author-id']]);
|
||||||
|
|
||||||
// send a notification
|
// send a notification
|
||||||
notification(
|
notification(
|
||||||
[
|
[
|
||||||
|
@ -2264,10 +2263,9 @@ class DFRN
|
||||||
"uid" => $importer["importer_uid"],
|
"uid" => $importer["importer_uid"],
|
||||||
"item" => $item,
|
"item" => $item,
|
||||||
"link" => System::baseUrl()."/display/".urlencode(Item::getGuidById($posted_id)),
|
"link" => System::baseUrl()."/display/".urlencode(Item::getGuidById($posted_id)),
|
||||||
"source_name" => stripslashes($item["author-name"]),
|
"source_name" => $author["name"],
|
||||||
"source_link" => $item["author-link"],
|
"source_link" => $author["url"],
|
||||||
"source_photo" => ((link_compare($item["author-link"], $importer["url"]))
|
"source_photo" => $author["thumb"],
|
||||||
? $importer["thumb"] : $item["author-avatar"]),
|
|
||||||
"verb" => $item["verb"],
|
"verb" => $item["verb"],
|
||||||
"otype" => "person",
|
"otype" => "person",
|
||||||
"activity" => $verb,
|
"activity" => $verb,
|
||||||
|
@ -2334,9 +2332,9 @@ class DFRN
|
||||||
// only one like or dislike per person
|
// only one like or dislike per person
|
||||||
// splitted into two queries for performance issues
|
// splitted into two queries for performance issues
|
||||||
$r = q(
|
$r = q(
|
||||||
"SELECT `id` FROM `item` WHERE `uid` = %d AND `author-link` = '%s' AND `verb` = '%s' AND `parent-uri` = '%s' AND NOT `deleted` LIMIT 1",
|
"SELECT `id` FROM `item` WHERE `uid` = %d AND `author-id` = %d AND `verb` = '%s' AND `parent-uri` = '%s' AND NOT `deleted` LIMIT 1",
|
||||||
intval($item["uid"]),
|
intval($item["uid"]),
|
||||||
dbesc($item["author-link"]),
|
intval($item["author-id"]),
|
||||||
dbesc($item["verb"]),
|
dbesc($item["verb"]),
|
||||||
dbesc($item["parent-uri"])
|
dbesc($item["parent-uri"])
|
||||||
);
|
);
|
||||||
|
@ -2345,9 +2343,9 @@ class DFRN
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q(
|
$r = q(
|
||||||
"SELECT `id` FROM `item` WHERE `uid` = %d AND `author-link` = '%s' AND `verb` = '%s' AND `thr-parent` = '%s' AND NOT `deleted` LIMIT 1",
|
"SELECT `id` FROM `item` WHERE `uid` = %d AND `author-id` = %d AND `verb` = '%s' AND `thr-parent` = '%s' AND NOT `deleted` LIMIT 1",
|
||||||
intval($item["uid"]),
|
intval($item["uid"]),
|
||||||
dbesc($item["author-link"]),
|
intval($item["author-id"]),
|
||||||
dbesc($item["verb"]),
|
dbesc($item["verb"]),
|
||||||
dbesc($item["parent-uri"])
|
dbesc($item["parent-uri"])
|
||||||
);
|
);
|
||||||
|
@ -2469,16 +2467,14 @@ class DFRN
|
||||||
// Fetch the owner
|
// Fetch the owner
|
||||||
$owner = self::fetchauthor($xpath, $entry, $importer, "dfrn:owner", true);
|
$owner = self::fetchauthor($xpath, $entry, $importer, "dfrn:owner", true);
|
||||||
|
|
||||||
$item["owner-name"] = $owner["name"];
|
|
||||||
$item["owner-link"] = $owner["link"];
|
$item["owner-link"] = $owner["link"];
|
||||||
$item["owner-avatar"] = $owner["avatar"];
|
$item["owner-id"] = Contact::getIdForURL($owner["link"], 0);
|
||||||
|
|
||||||
// fetch the author
|
// fetch the author
|
||||||
$author = self::fetchauthor($xpath, $entry, $importer, "atom:author", true);
|
$author = self::fetchauthor($xpath, $entry, $importer, "atom:author", true);
|
||||||
|
|
||||||
$item["author-name"] = $author["name"];
|
|
||||||
$item["author-link"] = $author["link"];
|
$item["author-link"] = $author["link"];
|
||||||
$item["author-avatar"] = $author["avatar"];
|
$item["author-id"] = Contact::getIdForURL($author["link"], 0);
|
||||||
|
|
||||||
$item["title"] = $xpath->query("atom:title/text()", $entry)->item(0)->nodeValue;
|
$item["title"] = $xpath->query("atom:title/text()", $entry)->item(0)->nodeValue;
|
||||||
|
|
||||||
|
@ -2736,9 +2732,8 @@ class DFRN
|
||||||
* but we're going to unconditionally correct it here so that the post will always be owned by our contact.
|
* but we're going to unconditionally correct it here so that the post will always be owned by our contact.
|
||||||
*/
|
*/
|
||||||
logger('Correcting item owner.', LOGGER_DEBUG);
|
logger('Correcting item owner.', LOGGER_DEBUG);
|
||||||
$item["owner-name"] = $importer["senderName"];
|
$item["owner-link"] = $importer["url"];
|
||||||
$item["owner-link"] = $importer["url"];
|
$item["owner-id"] = Contact::getIdForURL($importer["url"], 0);
|
||||||
$item["owner-avatar"] = $importer["thumb"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($importer["rel"] == CONTACT_IS_FOLLOWER) && (!self::tgroupCheck($importer["importer_uid"], $item))) {
|
if (($importer["rel"] == CONTACT_IS_FOLLOWER) && (!self::tgroupCheck($importer["importer_uid"], $item))) {
|
||||||
|
|
|
@ -69,7 +69,7 @@ class Diaspora
|
||||||
|
|
||||||
if (Config::get("system", "relay_directly", false)) {
|
if (Config::get("system", "relay_directly", false)) {
|
||||||
// We distribute our stuff based on the parent to ensure that the thread will be complete
|
// We distribute our stuff based on the parent to ensure that the thread will be complete
|
||||||
$parent = dba::selectFirst('item', ['parent'], ['id' => $item_id]);
|
$parent = Item::selectFirst(0, ['parent'], ['id' => $item_id]);
|
||||||
if (!DBM::is_result($parent)) {
|
if (!DBM::is_result($parent)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1170,15 +1170,10 @@ class Diaspora
|
||||||
*/
|
*/
|
||||||
private static function messageExists($uid, $guid)
|
private static function messageExists($uid, $guid)
|
||||||
{
|
{
|
||||||
$r = q(
|
$item = Item::selectFirst($uid, ['id'], ['uid' => $uid, 'guid' => $guid]);
|
||||||
"SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
|
if (DBM::is_result($item)) {
|
||||||
intval($uid),
|
|
||||||
dbesc($guid)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (DBM::is_result($r)) {
|
|
||||||
logger("message ".$guid." already exists for user ".$uid);
|
logger("message ".$guid." already exists for user ".$uid);
|
||||||
return $r[0]["id"];
|
return $item["id"];
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -1385,16 +1380,13 @@ class Diaspora
|
||||||
*/
|
*/
|
||||||
private static function parentItem($uid, $guid, $author, $contact)
|
private static function parentItem($uid, $guid, $author, $contact)
|
||||||
{
|
{
|
||||||
$r = q(
|
$fields = ['id', 'parent', 'body', 'wall', 'uri', 'guid', 'private', 'origin',
|
||||||
"SELECT `id`, `parent`, `body`, `wall`, `uri`, `guid`, `private`, `origin`,
|
'author-name', 'author-link', 'author-avatar',
|
||||||
`author-name`, `author-link`, `author-avatar`,
|
'owner-name', 'owner-link', 'owner-avatar'];
|
||||||
`owner-name`, `owner-link`, `owner-avatar`
|
$condition = ['uid' => $uid, 'guid' => $guid];
|
||||||
FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
|
$item = Item::selectFirst($uid, $fields, $condition);
|
||||||
intval($uid),
|
|
||||||
dbesc($guid)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!$r) {
|
if (!DBM::is_result($item)) {
|
||||||
$result = self::storeByGuid($guid, $contact["url"], $uid);
|
$result = self::storeByGuid($guid, $contact["url"], $uid);
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
|
@ -1405,23 +1397,16 @@ class Diaspora
|
||||||
if ($result) {
|
if ($result) {
|
||||||
logger("Fetched missing item ".$guid." - result: ".$result, LOGGER_DEBUG);
|
logger("Fetched missing item ".$guid." - result: ".$result, LOGGER_DEBUG);
|
||||||
|
|
||||||
$r = q(
|
$item = Item::selectFirst($uid, $fields, $condition);
|
||||||
"SELECT `id`, `body`, `wall`, `uri`, `private`, `origin`,
|
|
||||||
`author-name`, `author-link`, `author-avatar`,
|
|
||||||
`owner-name`, `owner-link`, `owner-avatar`
|
|
||||||
FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
|
|
||||||
intval($uid),
|
|
||||||
dbesc($guid)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$r) {
|
if (!DBM::is_result($item)) {
|
||||||
logger("parent item not found: parent: ".$guid." - user: ".$uid);
|
logger("parent item not found: parent: ".$guid." - user: ".$uid);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
logger("parent item found: parent: ".$guid." - user: ".$uid);
|
logger("parent item found: parent: ".$guid." - user: ".$uid);
|
||||||
return $r[0];
|
return $item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1602,7 +1587,7 @@ class Diaspora
|
||||||
*/
|
*/
|
||||||
private static function getUriFromGuid($author, $guid, $onlyfound = false)
|
private static function getUriFromGuid($author, $guid, $onlyfound = false)
|
||||||
{
|
{
|
||||||
$item = dba::selectFirst('item', ['uri'], ['guid' => $guid]);
|
$item = Item::selectFirst(0, ['uri'], ['guid' => $guid]);
|
||||||
if (DBM::is_result($item)) {
|
if (DBM::is_result($item)) {
|
||||||
return $item["uri"];
|
return $item["uri"];
|
||||||
} elseif (!$onlyfound) {
|
} elseif (!$onlyfound) {
|
||||||
|
@ -1632,9 +1617,9 @@ class Diaspora
|
||||||
*/
|
*/
|
||||||
private static function getGuidFromUri($uri, $uid)
|
private static function getGuidFromUri($uri, $uid)
|
||||||
{
|
{
|
||||||
$r = q("SELECT `guid` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($uri), intval($uid));
|
$item = Item::selectFirst($uid, ['guid'], ['uri' => $uri, 'uid' => $uid]);
|
||||||
if (DBM::is_result($r)) {
|
if (DBM::is_result($item)) {
|
||||||
return $r[0]["guid"];
|
return $item["guid"];
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1649,11 +1634,10 @@ class Diaspora
|
||||||
*/
|
*/
|
||||||
private static function importerForGuid($guid)
|
private static function importerForGuid($guid)
|
||||||
{
|
{
|
||||||
$item = dba::fetch_first("SELECT `uid` FROM `item` WHERE `origin` AND `guid` = ? LIMIT 1", $guid);
|
$item = Item::selectFirst(0, ['uid'], ['origin' => true, 'guid' => $guid]);
|
||||||
|
|
||||||
if (DBM::is_result($item)) {
|
if (DBM::is_result($item)) {
|
||||||
logger("Found user ".$item['uid']." as owner of item ".$guid, LOGGER_DEBUG);
|
logger("Found user ".$item['uid']." as owner of item ".$guid, LOGGER_DEBUG);
|
||||||
$contact = dba::fetch_first("SELECT * FROM `contact` WHERE `self` AND `uid` = ?", $item['uid']);
|
$contact = dba::selectFirst('contact', [], ['self' => true, 'uid' => $item['uid']]);
|
||||||
if (DBM::is_result($contact)) {
|
if (DBM::is_result($contact)) {
|
||||||
return $contact;
|
return $contact;
|
||||||
}
|
}
|
||||||
|
@ -1721,13 +1705,11 @@ class Diaspora
|
||||||
$datarray["contact-id"] = $author_contact["cid"];
|
$datarray["contact-id"] = $author_contact["cid"];
|
||||||
$datarray["network"] = $author_contact["network"];
|
$datarray["network"] = $author_contact["network"];
|
||||||
|
|
||||||
$datarray["author-name"] = $person["name"];
|
|
||||||
$datarray["author-link"] = $person["url"];
|
$datarray["author-link"] = $person["url"];
|
||||||
$datarray["author-avatar"] = ((x($person, "thumb")) ? $person["thumb"] : $person["photo"]);
|
$datarray["author-id"] = Contact::getIdForURL($person["url"], 0);
|
||||||
|
|
||||||
$datarray["owner-name"] = $contact["name"];
|
|
||||||
$datarray["owner-link"] = $contact["url"];
|
$datarray["owner-link"] = $contact["url"];
|
||||||
$datarray["owner-avatar"] = ((x($contact, "thumb")) ? $contact["thumb"] : $contact["photo"]);
|
$datarray["owner-id"] = Contact::getIdForURL($contact["url"], 0);
|
||||||
|
|
||||||
$datarray["guid"] = $guid;
|
$datarray["guid"] = $guid;
|
||||||
$datarray["uri"] = self::getUriFromGuid($author, $guid);
|
$datarray["uri"] = self::getUriFromGuid($author, $guid);
|
||||||
|
@ -2056,13 +2038,11 @@ class Diaspora
|
||||||
$datarray["contact-id"] = $author_contact["cid"];
|
$datarray["contact-id"] = $author_contact["cid"];
|
||||||
$datarray["network"] = $author_contact["network"];
|
$datarray["network"] = $author_contact["network"];
|
||||||
|
|
||||||
$datarray["author-name"] = $person["name"];
|
|
||||||
$datarray["author-link"] = $person["url"];
|
$datarray["author-link"] = $person["url"];
|
||||||
$datarray["author-avatar"] = ((x($person, "thumb")) ? $person["thumb"] : $person["photo"]);
|
$datarray["author-id"] = Contact::getIdForURL($person["url"], 0);
|
||||||
|
|
||||||
$datarray["owner-name"] = $contact["name"];
|
|
||||||
$datarray["owner-link"] = $contact["url"];
|
$datarray["owner-link"] = $contact["url"];
|
||||||
$datarray["owner-avatar"] = ((x($contact, "thumb")) ? $contact["thumb"] : $contact["photo"]);
|
$datarray["owner-id"] = Contact::getIdForURL($contact["url"], 0);
|
||||||
|
|
||||||
$datarray["guid"] = $guid;
|
$datarray["guid"] = $guid;
|
||||||
$datarray["uri"] = self::getUriFromGuid($author, $guid);
|
$datarray["uri"] = self::getUriFromGuid($author, $guid);
|
||||||
|
@ -2079,7 +2059,7 @@ class Diaspora
|
||||||
|
|
||||||
// like on comments have the comment as parent. So we need to fetch the toplevel parent
|
// like on comments have the comment as parent. So we need to fetch the toplevel parent
|
||||||
if ($parent_item["id"] != $parent_item["parent"]) {
|
if ($parent_item["id"] != $parent_item["parent"]) {
|
||||||
$toplevel = dba::selectFirst('item', ['origin'], ['id' => $parent_item["parent"]]);
|
$toplevel = Item::selectFirst($importer["uid"], ['origin'], ['id' => $parent_item["parent"]]);
|
||||||
$origin = $toplevel["origin"];
|
$origin = $toplevel["origin"];
|
||||||
} else {
|
} else {
|
||||||
$origin = $parent_item["origin"];
|
$origin = $parent_item["origin"];
|
||||||
|
@ -2216,7 +2196,7 @@ class Diaspora
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$item = dba::selectFirst('item', ['id'], ['guid' => $parent_guid, 'origin' => true, 'private' => false]);
|
$item = Item::selectFirst(0, ['id'], ['guid' => $parent_guid, 'origin' => true, 'private' => false]);
|
||||||
if (!DBM::is_result($item)) {
|
if (!DBM::is_result($item)) {
|
||||||
logger('Item not found, no origin or private: '.$parent_guid);
|
logger('Item not found, no origin or private: '.$parent_guid);
|
||||||
return false;
|
return false;
|
||||||
|
@ -2237,11 +2217,11 @@ class Diaspora
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send all existing comments and likes to the requesting server
|
// Send all existing comments and likes to the requesting server
|
||||||
$comments = dba::p("SELECT `item`.`id`, `item`.`verb`, `contact`.`self`
|
$comments = Item::select(0, ['id', 'verb', 'self'], ['parent' => $item['id']]);
|
||||||
FROM `item`
|
|
||||||
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
|
|
||||||
WHERE `item`.`parent` = ? AND `item`.`id` != `item`.`parent`", $item['id']);
|
|
||||||
while ($comment = dba::fetch($comments)) {
|
while ($comment = dba::fetch($comments)) {
|
||||||
|
if ($comment['id'] == $comment['parent']) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if ($comment['verb'] == ACTIVITY_POST) {
|
if ($comment['verb'] == ACTIVITY_POST) {
|
||||||
$cmd = $comment['self'] ? 'comment-new' : 'comment-import';
|
$cmd = $comment['self'] ? 'comment-new' : 'comment-import';
|
||||||
} else {
|
} else {
|
||||||
|
@ -2599,7 +2579,7 @@ class Diaspora
|
||||||
$fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
|
$fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
|
||||||
'author-name', 'author-link', 'author-avatar'];
|
'author-name', 'author-link', 'author-avatar'];
|
||||||
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
|
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
|
||||||
$item = dba::selectfirst('item', $fields, $condition);
|
$item = Item::selectFirst(0, $fields, $condition);
|
||||||
|
|
||||||
if (DBM::is_result($item)) {
|
if (DBM::is_result($item)) {
|
||||||
logger("reshared message ".$guid." already exists on system.");
|
logger("reshared message ".$guid." already exists on system.");
|
||||||
|
@ -2643,7 +2623,7 @@ class Diaspora
|
||||||
$fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
|
$fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
|
||||||
'author-name', 'author-link', 'author-avatar'];
|
'author-name', 'author-link', 'author-avatar'];
|
||||||
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
|
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
|
||||||
$item = dba::selectfirst('item', $fields, $condition);
|
$item = Item::selectFirst(0, $fields, $condition);
|
||||||
|
|
||||||
if (DBM::is_result($item)) {
|
if (DBM::is_result($item)) {
|
||||||
// If it is a reshared post from another network then reformat to avoid display problems with two share elements
|
// If it is a reshared post from another network then reformat to avoid display problems with two share elements
|
||||||
|
@ -2701,13 +2681,11 @@ class Diaspora
|
||||||
$datarray["contact-id"] = $contact["id"];
|
$datarray["contact-id"] = $contact["id"];
|
||||||
$datarray["network"] = NETWORK_DIASPORA;
|
$datarray["network"] = NETWORK_DIASPORA;
|
||||||
|
|
||||||
$datarray["author-name"] = $contact["name"];
|
|
||||||
$datarray["author-link"] = $contact["url"];
|
$datarray["author-link"] = $contact["url"];
|
||||||
$datarray["author-avatar"] = ((x($contact, "thumb")) ? $contact["thumb"] : $contact["photo"]);
|
$datarray["author-id"] = Contact::getIdForURL($contact["url"], 0);
|
||||||
|
|
||||||
$datarray["owner-name"] = $datarray["author-name"];
|
|
||||||
$datarray["owner-link"] = $datarray["author-link"];
|
$datarray["owner-link"] = $datarray["author-link"];
|
||||||
$datarray["owner-avatar"] = $datarray["author-avatar"];
|
$datarray["owner-id"] = $datarray["author-id"];
|
||||||
|
|
||||||
$datarray["guid"] = $guid;
|
$datarray["guid"] = $guid;
|
||||||
$datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
|
$datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
|
||||||
|
@ -2787,7 +2765,7 @@ class Diaspora
|
||||||
} else {
|
} else {
|
||||||
$condition = ["`guid` = ? AND `uid` = ? AND NOT `file` LIKE '%%[%%' AND NOT `deleted`", $target_guid, $importer['uid']];
|
$condition = ["`guid` = ? AND `uid` = ? AND NOT `file` LIKE '%%[%%' AND NOT `deleted`", $target_guid, $importer['uid']];
|
||||||
}
|
}
|
||||||
$r = dba::select('item', $fields, $condition);
|
$r = Item::select($importer['uid'], $fields, $condition);
|
||||||
if (!DBM::is_result($r)) {
|
if (!DBM::is_result($r)) {
|
||||||
logger("Target guid ".$target_guid." was not found on this system for user ".$importer['uid'].".");
|
logger("Target guid ".$target_guid." was not found on this system for user ".$importer['uid'].".");
|
||||||
return false;
|
return false;
|
||||||
|
@ -2795,7 +2773,7 @@ class Diaspora
|
||||||
|
|
||||||
while ($item = dba::fetch($r)) {
|
while ($item = dba::fetch($r)) {
|
||||||
// Fetch the parent item
|
// Fetch the parent item
|
||||||
$parent = dba::selectFirst('item', ['author-link'], ['id' => $item["parent"]]);
|
$parent = Item::selectFirst(0, ['author-link'], ['id' => $item["parent"]]);
|
||||||
|
|
||||||
// Only delete it if the parent author really fits
|
// Only delete it if the parent author really fits
|
||||||
if (!link_compare($parent["author-link"], $contact["url"]) && !link_compare($item["author-link"], $contact["url"])) {
|
if (!link_compare($parent["author-link"], $contact["url"]) && !link_compare($item["author-link"], $contact["url"])) {
|
||||||
|
@ -2921,13 +2899,11 @@ class Diaspora
|
||||||
$datarray["contact-id"] = $contact["id"];
|
$datarray["contact-id"] = $contact["id"];
|
||||||
$datarray["network"] = NETWORK_DIASPORA;
|
$datarray["network"] = NETWORK_DIASPORA;
|
||||||
|
|
||||||
$datarray["author-name"] = $contact["name"];
|
|
||||||
$datarray["author-link"] = $contact["url"];
|
$datarray["author-link"] = $contact["url"];
|
||||||
$datarray["author-avatar"] = ((x($contact, "thumb")) ? $contact["thumb"] : $contact["photo"]);
|
$datarray["author-id"] = Contact::getIdForURL($contact["url"], 0);
|
||||||
|
|
||||||
$datarray["owner-name"] = $datarray["author-name"];
|
|
||||||
$datarray["owner-link"] = $datarray["author-link"];
|
$datarray["owner-link"] = $datarray["author-link"];
|
||||||
$datarray["owner-avatar"] = $datarray["author-avatar"];
|
$datarray["owner-id"] = $datarray["author-id"];
|
||||||
|
|
||||||
$datarray["guid"] = $guid;
|
$datarray["guid"] = $guid;
|
||||||
$datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
|
$datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
|
||||||
|
@ -3433,7 +3409,7 @@ class Diaspora
|
||||||
|
|
||||||
if (($guid != "") && $complete) {
|
if (($guid != "") && $complete) {
|
||||||
$condition = ['guid' => $guid, 'network' => [NETWORK_DFRN, NETWORK_DIASPORA]];
|
$condition = ['guid' => $guid, 'network' => [NETWORK_DFRN, NETWORK_DIASPORA]];
|
||||||
$item = dba::selectFirst('item', ['contact-id'], $condition);
|
$item = Item::selectFirst(0, ['contact-id'], $condition);
|
||||||
if (DBM::is_result($item)) {
|
if (DBM::is_result($item)) {
|
||||||
$ret= [];
|
$ret= [];
|
||||||
$ret["root_handle"] = self::handleFromContact($item["contact-id"]);
|
$ret["root_handle"] = self::handleFromContact($item["contact-id"]);
|
||||||
|
@ -3700,16 +3676,11 @@ class Diaspora
|
||||||
*/
|
*/
|
||||||
private static function constructLike($item, $owner)
|
private static function constructLike($item, $owner)
|
||||||
{
|
{
|
||||||
$p = q(
|
$parent = Item::selectFirst(0, ['guid', 'uri', 'parent-uri'], ['uri' => $item["thr-parent"]]);
|
||||||
"SELECT `guid`, `uri`, `parent-uri` FROM `item` WHERE `uri` = '%s' LIMIT 1",
|
if (!DBM::is_result($parent)) {
|
||||||
dbesc($item["thr-parent"])
|
|
||||||
);
|
|
||||||
if (!DBM::is_result($p)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent = $p[0];
|
|
||||||
|
|
||||||
$target_type = ($parent["uri"] === $parent["parent-uri"] ? "Post" : "Comment");
|
$target_type = ($parent["uri"] === $parent["parent-uri"] ? "Post" : "Comment");
|
||||||
$positive = null;
|
$positive = null;
|
||||||
if ($item['verb'] === ACTIVITY_LIKE) {
|
if ($item['verb'] === ACTIVITY_LIKE) {
|
||||||
|
@ -3736,16 +3707,11 @@ class Diaspora
|
||||||
*/
|
*/
|
||||||
private static function constructAttend($item, $owner)
|
private static function constructAttend($item, $owner)
|
||||||
{
|
{
|
||||||
$p = q(
|
$parent = Item::selectFirst(0, ['guid', 'uri', 'parent-uri'], ['uri' => $item["thr-parent"]]);
|
||||||
"SELECT `guid`, `uri`, `parent-uri` FROM `item` WHERE `uri` = '%s' LIMIT 1",
|
if (!DBM::is_result($parent)) {
|
||||||
dbesc($item["thr-parent"])
|
|
||||||
);
|
|
||||||
if (!DBM::is_result($p)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent = $p[0];
|
|
||||||
|
|
||||||
switch ($item['verb']) {
|
switch ($item['verb']) {
|
||||||
case ACTIVITY_ATTEND:
|
case ACTIVITY_ATTEND:
|
||||||
$attend_answer = 'accepted';
|
$attend_answer = 'accepted';
|
||||||
|
@ -3785,18 +3751,11 @@ class Diaspora
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
$p = q(
|
$parent = Item::selectFirst(0, ['guid'], ['id' => $item["parent"], 'parent' => $item["parent"]]);
|
||||||
"SELECT `guid` FROM `item` WHERE `parent` = %d AND `id` = %d LIMIT 1",
|
if (!DBM::is_result($parent)) {
|
||||||
intval($item["parent"]),
|
|
||||||
intval($item["parent"])
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!DBM::is_result($p)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$parent = $p[0];
|
|
||||||
|
|
||||||
$text = html_entity_decode(BBCode::toMarkdown($item["body"]));
|
$text = html_entity_decode(BBCode::toMarkdown($item["body"]));
|
||||||
$created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
|
$created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
|
||||||
|
|
||||||
|
@ -4265,16 +4224,16 @@ class Diaspora
|
||||||
|
|
||||||
$contact["uprvkey"] = $r[0]['prvkey'];
|
$contact["uprvkey"] = $r[0]['prvkey'];
|
||||||
|
|
||||||
$r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", intval($post_id));
|
$item = Item::selectFirst(0, [], ['id' => $post_id]);
|
||||||
if (!DBM::is_result($r)) {
|
if (!DBM::is_result($item)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_array($r[0]["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
|
if (!in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$message = self::constructLike($r[0], $contact);
|
$message = self::constructLike($item, $contact);
|
||||||
if ($message === false) {
|
if ($message === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue