- $condition = ["`parent` = ? OR `parent-uri` = ? AND `parent` = `id`", $item_id, $item_id];
- $item = Item::selectFirst([], $condition);
-
- if (empty($item_id) || !DBA::isResult($item)) {
- Logger::log('subthread: no item ' . $item_id);
- return;
- }
-
- $owner_uid = $item['uid'];
-
- if (!Security::canWriteToUserWall($owner_uid)) {
- return;
- }
-
- $remote_owner = null;
-
- if (!$item['wall']) {
- // The top level post may have been written by somebody on another system
- $contact = DBA::selectFirst('contact', [], ['id' => $item['contact-id'], 'uid' => $item['uid']]);
- if (!DBA::isResult($contact)) {
- return;
- }
- if (!$contact['self']) {
- $remote_owner = $contact;
- }
- }
-
- $owner = null;
- // this represents the post owner on this system.
-
- $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
- WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
- intval($owner_uid)
- );
-
- if (DBA::isResult($r)) {
- $owner = $r[0];
- }
-
- if (!$owner) {
- Logger::log('like: no owner');
- return;
- }
-
- if (!$remote_owner) {
- $remote_owner = $owner;
- }
-
- $contact = null;
- // This represents the person posting
-
- if (local_user() && (local_user() == $owner_uid)) {
- $contact = $owner;
- } else {
- $contact = DBA::selectFirst('contact', [], ['id' => $_SESSION['visitor_id'], 'uid' => $owner_uid]);
- if (!DBA::isResult($contact)) {
- return;
- }
- }
-
- $uri = Item::newURI($owner_uid);
-
- $post_type = (($item['resource-id']) ? L10n::t('photo') : L10n::t('status'));
- $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_IMAGE : ACTIVITY_OBJ_NOTE );
- $link = XML::escape('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n");
- $body = $item['body'];
-
- $obj = <<< EOT
-
- <object>
- <type>$objtype</type>
- <local>1</local>
- <id>{$item['uri']}</id>
- <link>$link</link>
- <title></title>
- <content>$body</content>
- </object>
-EOT;
- $bodyverb = L10n::t('%1$s is following %2$s\'s %3$s');
-
- if (!isset($bodyverb)) {
- return;