From 5fc1eebdab0c0a7d289fe97eeab292cf3fd1be20 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sun, 1 May 2016 00:19:24 +0200 Subject: [PATCH] Copy an item to the local user if it's only available as public copy --- mod/display.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/mod/display.php b/mod/display.php index fbbd26317..a759d037e 100644 --- a/mod/display.php +++ b/mod/display.php @@ -16,7 +16,7 @@ function display_init(&$a) { // Does the local user have this item? if (local_user()) { - $r = q("SELECT `id`, `parent`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item` + $r = q("SELECT `id`, `parent`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid`, `owner-link` FROM `item` WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND `guid` = '%s' AND `uid` = %d", dbesc($a->argv[1]), local_user()); if (count($r)) { @@ -28,7 +28,7 @@ function display_init(&$a) { // Or is it anywhere on the server? if ($nick == "") { $r = q("SELECT `user`.`nickname`, `item`.`id`, `item`.`parent`, `item`.`author-name`, - `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`body` + `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`owner-link`, `item`.`body` FROM `item` INNER JOIN `user` ON `user`.`uid` = `item`.`uid` WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' @@ -44,8 +44,8 @@ function display_init(&$a) { // Is it an item with uid=0? if ($nick == "") { - $r = q("SELECT `item`.`id`, `item`.`parent`, `item`.`author-name`, - `item`.`author-link`, `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`body` + $r = q("SELECT `item`.`id`, `item`.`parent`, `item`.`author-name`, `item`.`author-link`, + `item`.`author-avatar`, `item`.`network`, `item`.`uid`, `item`.`owner-link`, `item`.`body` FROM `item` WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND `item`.`allow_cid` = '' AND `item`.`allow_gid` = '' AND `item`.`deny_cid` = '' AND `item`.`deny_gid` = '' @@ -55,10 +55,25 @@ function display_init(&$a) { } if (count($r)) { if ($r[0]["id"] != $r[0]["parent"]) - $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid` FROM `item` + $r = q("SELECT `id`, `author-name`, `author-link`, `author-avatar`, `network`, `body`, `uid`, `owner-link` FROM `item` WHERE `item`.`visible` AND NOT `item`.`deleted` AND NOT `item`.`moderated` AND `id` = %d", $r[0]["parent"]); + if (($itemuid != local_user()) AND local_user()) { + // Do we know this contact but we haven't got this item? + // Copy it to our local storage. + $contactid = get_contact($r[0]['owner-link'], local_user()); + if ($contactid) { + $item = q("SELECT * FROM `item` WHERE `id` = %d", intval($r[0]["id"])); + unset($item[0]['id']); + $item[0]['uid'] = local_user(); + $item[0]['origin'] = 0; + $item[0]['contact-id'] = $contactid; + $local_copy = item_store($item[0], false, false, true); + logger("Stored local copy for post ".$item[0]['id']." under id ".$local_copy, LOGGER_DEBUG); + } + } + $profiledata = display_fetchauthor($a, $r[0]); if (strstr(normalise_link($profiledata["url"]), normalise_link($a->get_baseurl()))) {