diff --git a/database.sql b/database.sql index 6f4d9ca791..ffe02585e2 100644 --- a/database.sql +++ b/database.sql @@ -514,6 +514,7 @@ CREATE TABLE IF NOT EXISTS `item` ( `network` char(4) NOT NULL DEFAULT '' COMMENT 'Network from where the item comes from', `rendered-hash` varchar(32) NOT NULL DEFAULT '' COMMENT '', `rendered-html` mediumtext COMMENT 'item.body converted to html', + `global` boolean NOT NULL DEFAULT '0' COMMENT '', PRIMARY KEY(`id`), INDEX `guid` (`guid`(191)), INDEX `uri` (`uri`(191)), diff --git a/include/api.php b/include/api.php index 4dce85ed50..94adecf0c0 100644 --- a/include/api.php +++ b/include/api.php @@ -1632,7 +1632,7 @@ function api_search($type) $r = dba::p( "SELECT ".item_fieldlists()." FROM `item` ".item_joins(api_user())." - WHERE ".item_condition()." AND (`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`public`)) + WHERE ".item_condition()." AND (`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`)) AND `item`.`body` LIKE CONCAT('%',?,'%') $sql_extra AND `item`.`id`>? @@ -2066,7 +2066,7 @@ function api_conversation_show($type) $sql_extra = ' AND `item`.`id` <= ' . intval($max_id); } - $r = q("SELECT `item`.`*` FROM `item` + $r = q("SELECT `item`.* FROM `item` STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`) WHERE `item`.`parent` = %d AND `item`.`visible` diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index 03146dd5de..f5c778b219 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -1195,6 +1195,7 @@ class DBStructure "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network from where the item comes from"], "rendered-hash" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""], "rendered-html" => ["type" => "mediumtext", "comment" => "item.body converted to html"], + "global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""], ], "indexes" => [ "PRIMARY" => ["id"], diff --git a/src/Model/Item.php b/src/Model/Item.php index 1b64aafd01..c15d10f197 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -724,6 +724,16 @@ class Item extends BaseObject } } + // Is this item available in the global items (with uid=0)? + if ($item["uid"] == 0) { + $item["global"] = true; + + // Set the global flag on all items if this was a global item entry + dba::update('item', ['global' => true], ['uri' => $item["uri"]]); + } else { + $item["global"] = dba::exists('item', ['uid' => 0, 'uri' => $item["uri"]]); + } + // ACL settings if (strlen($allow_cid) || strlen($allow_gid) || strlen($deny_cid) || strlen($deny_gid)) { $private = 1;