- $arr['type'] = 'remote';
- $arr['wall'] = ((intval($arr['wall'])) ? 1 : 0);
- $arr['uri'] = notags(trim($arr['uri']));
- $arr['author-name'] = notags(trim($arr['author-name']));
- $arr['author-link'] = notags(trim($arr['author-link']));
- $arr['author-avatar'] = notags(trim($arr['author-avatar']));
- $arr['owner-name'] = notags(trim($arr['owner-name']));
- $arr['owner-link'] = notags(trim($arr['owner-link']));
- $arr['owner-avatar'] = notags(trim($arr['owner-avatar']));
- $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
- $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
- $arr['changed'] = datetime_convert();
- $arr['title'] = notags(trim($arr['title']));
- $arr['location'] = notags(trim($arr['location']));
- $arr['body'] = escape_tags(trim($arr['body']));
- $arr['last-child'] = intval($arr['last-child']);
- $arr['visible'] = ((x($arr,'visible') !== false) ? intval($arr['visible']) : 1);
- $arr['deleted'] = 0;
- $arr['parent-uri'] = notags(trim($arr['parent-uri']));
- $arr['verb'] = notags(trim($arr['verb']));
- $arr['object-type'] = notags(trim($arr['object-type']));
- $arr['object'] = trim($arr['object']);
-
- $parent_id = 0;
- $parent_missing = false;
+ $arr['type'] = 'remote';
+ $arr['wall'] = ((x($arr,'wall')) ? intval($arr['wall']) : 0);
+ $arr['uri'] = ((x($arr,'uri')) ? notags(trim($arr['uri'])) : random_string());
+ $arr['author-name'] = ((x($arr,'author-name')) ? notags(trim($arr['author-name'])) : '');
+ $arr['author-link'] = ((x($arr,'author-link')) ? notags(trim($arr['author-link'])) : '');
+ $arr['author-avatar'] = ((x($arr,'author-avatar')) ? notags(trim($arr['author-avatar'])) : '');
+ $arr['owner-name'] = ((x($arr,'owner-name')) ? notags(trim($arr['owner-name'])) : '');
+ $arr['owner-link'] = ((x($arr,'owner-link')) ? notags(trim($arr['owner-link'])) : '');
+ $arr['owner-avatar'] = ((x($arr,'owner-avatar')) ? notags(trim($arr['owner-avatar'])) : '');
+ $arr['created'] = ((x($arr,'created') !== false) ? datetime_convert('UTC','UTC',$arr['created']) : datetime_convert());
+ $arr['edited'] = ((x($arr,'edited') !== false) ? datetime_convert('UTC','UTC',$arr['edited']) : datetime_convert());
+ $arr['changed'] = datetime_convert();
+ $arr['title'] = ((x($arr,'title')) ? notags(trim($arr['title'])) : '');
+ $arr['location'] = ((x($arr,'location')) ? notags(trim($arr['location'])) : '');
+ $arr['coord'] = ((x($arr,'coord')) ? notags(trim($arr['coord'])) : '');
+ $arr['last-child'] = ((x($arr,'last-child')) ? intval($arr['last-child']) : 0 );
+ $arr['visible'] = ((x($arr,'visible') !== false) ? intval($arr['visible']) : 1 );
+ $arr['deleted'] = 0;
+ $arr['parent-uri'] = ((x($arr,'parent-uri')) ? notags(trim($arr['parent-uri'])) : '');
+ $arr['verb'] = ((x($arr,'verb')) ? notags(trim($arr['verb'])) : '');
+ $arr['object-type'] = ((x($arr,'object-type')) ? notags(trim($arr['object-type'])) : '');
+ $arr['object'] = ((x($arr,'object')) ? trim($arr['object']) : '');
+ $arr['target-type'] = ((x($arr,'target-type')) ? notags(trim($arr['target-type'])) : '');
+ $arr['target'] = ((x($arr,'target')) ? trim($arr['target']) : '');
+ $arr['allow_cid'] = ((x($arr,'allow_cid')) ? trim($arr['allow_cid']) : '');
+ $arr['allow_gid'] = ((x($arr,'allow_gid')) ? trim($arr['allow_gid']) : '');
+ $arr['deny_cid'] = ((x($arr,'deny_cid')) ? trim($arr['deny_cid']) : '');
+ $arr['deny_gid'] = ((x($arr,'deny_gid')) ? trim($arr['deny_gid']) : '');
+ $arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0 );
+ $arr['body'] = ((x($arr,'body')) ? escape_tags(trim($arr['body'])) : '');
+
+ // The content body has been through a lot of filtering and transport escaping by now.
+ // We don't want to skip any filters, however a side effect of all this filtering
+ // is that ampersands and <> may have been double encoded, depending on which filter chain
+ // they came through.
+
+ $arr['body'] = str_replace(
+ array('&amp;', '&gt;', '&lt;', '&quot;'),
+ array('&' , '>' , '<', '"'),
+ $arr['body']
+ );
+
+
+
+ if($arr['parent-uri'] === $arr['uri']) {
+ $parent_id = 0;
+ $allow_cid = $arr['allow_cid'];
+ $allow_gid = $arr['allow_gid'];
+ $deny_cid = $arr['deny_cid'];
+ $deny_gid = $arr['deny_gid'];
+ }
+ else {
+
+ // find the parent and snarf the item id and ACL's
+
+ $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
+ dbesc($arr['parent-uri']),
+ intval($arr['uid'])
+ );
+
+ if(count($r)) {
+
+ // is the new message multi-level threaded?
+ // even though we don't support it now, preserve the info
+ // and re-attach to the conversation parent.
+
+ if($r[0]['uri'] != $r[0]['parent-uri']) {
+ $arr['thr-parent'] = $arr['parent-uri'];
+ $arr['parent-uri'] = $r[0]['parent-uri'];
+ }
+
+ $parent_id = $r[0]['id'];
+ $allow_cid = $r[0]['allow_cid'];
+ $allow_gid = $r[0]['allow_gid'];
+ $deny_cid = $r[0]['deny_cid'];
+ $deny_gid = $r[0]['deny_gid'];
+ }
+ else {
+ logger('item_store: item parent was not found - ignoring item');
+ return 0;
+ }
+ }
+
+ call_hooks('post_remote',$arr);