- /**
- * Fetches a message with a given guid
- *
- * @param string $guid message guid
- * @param string $orig_author handle of the original post
- * @return array The fetched item
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- * @throws \ImagickException
- */
- public static function originalItem($guid, $orig_author)
- {
- if (empty($guid)) {
- Logger::notice('Empty guid. Quitting.');
- return false;
- }
-
- // Do we already have this item?
- $fields = ['body', 'title', 'app', 'created', 'object-type', 'uri', 'guid',
- 'author-name', 'author-link', 'author-avatar', 'plink', 'uri-id'];
- $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]];
- $item = Post::selectFirst($fields, $condition);
-
- if (DBA::isResult($item)) {
- Logger::notice("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($item["body"], true)) {
- $item = [];
- } elseif (self::isReshare($item["body"], false) || strstr($item["body"], "[share")) {
- $item["body"] = Markdown::toBBCode(BBCode::toMarkdown($item["body"]));
-
- $item["body"] = self::replacePeopleGuid($item["body"], $item["author-link"]);
-
- return $item;
- } else {
- return $item;
- }
- }
-
- if (!DBA::isResult($item)) {
- if (empty($orig_author)) {
- Logger::notice('Empty author for guid ' . $guid . '. Quitting.');
- return false;
- }
-
- $server = "https://".substr($orig_author, strpos($orig_author, "@") + 1);
- Logger::notice("1st try: reshared message ".$guid." will be fetched via SSL from the server ".$server);
- $stored = self::storeByGuid($guid, $server);
-
- if (!$stored) {
- $server = "http://".substr($orig_author, strpos($orig_author, "@") + 1);
- Logger::notice("2nd try: reshared message ".$guid." will be fetched without SSL from the server ".$server);
- $stored = self::storeByGuid($guid, $server);
- }
-
- if ($stored) {
- $fields = ['body', 'title', 'app', 'created', 'object-type', 'uri', 'guid',
- 'author-name', 'author-link', 'author-avatar', 'plink', 'uri-id'];
- $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]];
- $item = Post::selectFirst($fields, $condition);
-
- if (DBA::isResult($item)) {
- // If it is a reshared post from another network then reformat to avoid display problems with two share elements
- if (self::isReshare($item["body"], false)) {
- $item["body"] = Markdown::toBBCode(BBCode::toMarkdown($item["body"]));
- $item["body"] = self::replacePeopleGuid($item["body"], $item["author-link"]);
- }
-
- return $item;
- }
- }
- }
- return false;
- }
-