- // Get the parent
- $parents = q("SELECT `item`.`id`, `item`.`parent`, `item`.`uri`, `item`.`contact-id`, `item`.`type`,
- `item`.`verb`, `item`.`visible` FROM `term`
- STRAIGHT_JOIN `item` AS `thritem` ON `thritem`.`parent` = `term`.`oid`
- STRAIGHT_JOIN `item` ON `item`.`parent` = `thritem`.`parent`
- WHERE `term`.`uid` = %d AND `term`.`otype` = %d AND `term`.`type` = %d AND `term`.`url` = '%s'",
- intval($uid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($conversation_url));
-
-/* 2016-10-23: The old query will be kept until we are sure that the query above is a good and fast replacement
-
- $parents = q("SELECT `id`, `parent`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `id` IN
- (SELECT `parent` FROM `item` WHERE `id` IN
- (SELECT `oid` FROM `term` WHERE `uid` = %d AND `otype` = %d AND `type` = %d AND `url` = '%s'))",
- intval($uid), intval(TERM_OBJ_POST), intval(TERM_CONVERSATION), dbesc($conversation_url));
-*/
- if ($parents)
- $parent = $parents[0];
- elseif (count($item) > 0) {
- $parent = $item;
- $parent["type"] = "remote";
- $parent["verb"] = ACTIVITY_POST;
- $parent["visible"] = 1;
- } else {
- // Preset the parent
- $r = q("SELECT `id` FROM `contact` WHERE `self` AND `uid`=%d", $uid);
- if (!$r)
- return(-2);
-
- $parent = array();
- $parent["id"] = 0;
- $parent["parent"] = 0;
- $parent["uri"] = "";
- $parent["contact-id"] = $r[0]["id"];
- $parent["type"] = "remote";
- $parent["verb"] = ACTIVITY_POST;
- $parent["visible"] = 1;
- }
-
- $conv = str_replace("/conversation/", "/api/statusnet/conversation/", $conversation_url).".as";
- $pageno = 1;
- $items = array();
-
- logger('fetching conversation url '.$conv.' (Self: '.$self.') for user '.$uid);
-
- do {
- $conv_arr = z_fetch_url($conv."?page=".$pageno);
-
- // If it is a non-ssl site and there is an error, then try ssl or vice versa
- if (!$conv_arr["success"] AND (substr($conv, 0, 7) == "http://")) {
- $conv = str_replace("http://", "https://", $conv);
- $conv_as = fetch_url($conv."?page=".$pageno);
- } elseif (!$conv_arr["success"] AND (substr($conv, 0, 8) == "https://")) {
- $conv = str_replace("https://", "http://", $conv);
- $conv_as = fetch_url($conv."?page=".$pageno);
- } else
- $conv_as = $conv_arr["body"];
-
- $conv_as = str_replace(',"statusnet:notice_info":', ',"statusnet_notice_info":', $conv_as);
- $conv_as = json_decode($conv_as);
-
- $no_of_items = sizeof($items);
-
- if (@is_array($conv_as->items))
- foreach ($conv_as->items AS $single_item)
- $items[$single_item->id] = $single_item;
-
- if ($no_of_items == sizeof($items))
- break;
-
- $pageno++;
-
- } while (true);
-
- logger('fetching conversation done. Found '.count($items).' items');