+
+ // look for a 'references' or an 'in-reply-to' header and try to match with a parent item we have locally.
+
+// $raw_refs = ((x($headers,'references')) ? str_replace("\t",'',$headers['references']) : '');
+ $raw_refs = ((property_exists($meta,'references')) ? str_replace("\t",'',$meta->references) : '');
+ if(! trim($raw_refs))
+ $raw_refs = ((property_exists($meta,'in_reply_to')) ? str_replace("\t",'',$meta->in_reply_to) : '');
+ $raw_refs = trim($raw_refs); // Don't allow a blank reference in $refs_arr
+
+ if($raw_refs) {
+ $refs_arr = explode(' ', $raw_refs);
+ if(count($refs_arr)) {
+ for($x = 0; $x < count($refs_arr); $x ++)
+ $refs_arr[$x] = "'" . msgid2iri(str_replace(array('<','>',' '),array('','',''),dbesc($refs_arr[$x]))) . "'";
+ }
+ $qstr = implode(',',$refs_arr);
+ $r = q("SELECT `uri` , `parent-uri` FROM `item` WHERE `uri` IN ( $qstr ) AND `uid` = %d LIMIT 1",
+ intval($importer_uid)
+ );
+ if(count($r))
+ $datarray['parent-uri'] = $r[0]['parent-uri']; // Set the parent as the top-level item
+// $datarray['parent-uri'] = $r[0]['uri'];
+ }
+
+
+ if(! x($datarray,'parent-uri'))
+ $datarray['parent-uri'] = $datarray['uri'];
+