diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 6c47aadc7..733cdf743 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -2747,32 +2747,30 @@ class Diaspora public static function originalItem($guid, $orig_author) { // Do we already have this item? - $r = q( - "SELECT `body`, `tag`, `app`, `created`, `object-type`, `uri`, `guid`, - `author-name`, `author-link`, `author-avatar` - FROM `item` WHERE `guid` = '%s' AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1", - dbesc($guid) - ); + $fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid', + 'author-name', 'author-link', 'author-avatar']; + $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false]; + $item = dba::selectfirst('item', $fields, $condition); - if (DBM::is_result($r)) { + if (DBM::is_result($item)) { logger("reshared message ".$guid." already exists on system."); // Maybe it is already a reshared item? // Then refetch the content, if it is a reshare from a reshare. // If it is a reshared post from another network then reformat to avoid display problems with two share elements - if (self::isReshare($r[0]["body"], true)) { + if (self::isReshare($item["body"], true)) { $r = []; - } elseif (self::isReshare($r[0]["body"], false) || strstr($r[0]["body"], "[share")) { - $r[0]["body"] = Markdown::toBBCode(BBCode::toMarkdown($r[0]["body"])); + } elseif (self::isReshare($item["body"], false) || strstr($item["body"], "[share")) { + $item["body"] = Markdown::toBBCode(BBCode::toMarkdown($item["body"])); - $r[0]["body"] = self::replacePeopleGuid($r[0]["body"], $r[0]["author-link"]); + $item["body"] = self::replacePeopleGuid($item["body"], $item["author-link"]); // Add OEmbed and other information to the body - $r[0]["body"] = add_page_info_to_body($r[0]["body"], false, true); + $item["body"] = add_page_info_to_body($item["body"], false, true); - return $r[0]; + return $item; } else { - return $r[0]; + return $item; } } @@ -2788,21 +2786,19 @@ class Diaspora } if ($item_id) { - $r = q( - "SELECT `body`, `tag`, `app`, `created`, `object-type`, `uri`, `guid`, - `author-name`, `author-link`, `author-avatar` - FROM `item` WHERE `id` = %d AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1", - intval($item_id) - ); + $fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid', + 'author-name', 'author-link', 'author-avatar']; + $condition = ['id' => $item_id, 'visible' => true, 'deleted' => false]; + $item = dba::selectfirst('item', $fields, $condition); - if (DBM::is_result($r)) { + 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 (self::isReshare($r[0]["body"], false)) { - $r[0]["body"] = Markdown::toBBCode(BBCode::toMarkdown($r[0]["body"])); - $r[0]["body"] = self::replacePeopleGuid($r[0]["body"], $r[0]["author-link"]); + if (self::isReshare($item["body"], false)) { + $item["body"] = Markdown::toBBCode(BBCode::toMarkdown($item["body"])); + $item["body"] = self::replacePeopleGuid($item["body"], $item["author-link"]); } - return $r[0]; + return $item; } } } @@ -3584,15 +3580,11 @@ class Diaspora } if (($guid != "") && $complete) { - $r = q( - "SELECT `contact-id` FROM `item` WHERE `guid` = '%s' AND `network` IN ('%s', '%s') LIMIT 1", - dbesc($guid), - NETWORK_DFRN, - NETWORK_DIASPORA - ); - if ($r) { + $condition = ['guid' => $guid, 'network' => [NETWORK_DFRN, NETWORK_DIASPORA]]; + $item = dba::selectFirst('item', ['contact-id'], $condition); + if (DBM::is_result($item)) { $ret= []; - $ret["root_handle"] = self::handleFromContact($r[0]["contact-id"]); + $ret["root_handle"] = self::handleFromContact($item["contact-id"]); $ret["root_guid"] = $guid; return $ret; }