Diaspora: Store the original XML and the object type.

This commit is contained in:
Michael Vogel 2015-05-25 13:27:45 +02:00
parent dc182d508e
commit 0c752a2190
1 changed files with 47 additions and 11 deletions

View File

@ -833,12 +833,19 @@ function diaspora_post($importer,$xml,$msg) {
$body = diaspora2bb($xml->raw_message);
// Add OEmbed and other information to the body
if (!diaspora_is_redmatrix($contact['url']))
$body = add_page_info_to_body($body, false, true);
$datarray = array();
$datarray["object"] = json_encode($xml);
if($xml->photo->remote_photo_path AND $xml->photo->remote_photo_name)
$datarray["object-type"] = ACTIVITY_OBJ_PHOTO;
else {
$datarray['object-type'] = ACTIVITY_OBJ_NOTE;
// Add OEmbed and other information to the body
if (!diaspora_is_redmatrix($contact['url']))
$body = add_page_info_to_body($body, false, true);
}
$str_tags = '';
$cnt = preg_match_all('/@\[url=(.*?)\[\/url\]/ism',$body,$matches,PREG_SET_ORDER);
@ -872,7 +879,10 @@ function diaspora_post($importer,$xml,$msg) {
$datarray['author-avatar'] = $contact['thumb'];
$datarray['body'] = $body;
$datarray['tag'] = $str_tags;
$datarray['app'] = 'Diaspora';
if ($xml->provider_display_name)
$datarray["app"] = unxmlify($xml->provider_display_name);
else
$datarray['app'] = 'Diaspora';
// if empty content it might be a photo that hasn't arrived yet. If a photo arrives, we'll make it visible.
@ -921,6 +931,8 @@ function diaspora_store_by_guid($guid, $server, $uid = 0) {
$author = $item["author"];
$guid = $item["guid"];
$private = $item["private"];
$object = $item["object"];
$objecttype = $item["object-type"];
$message_id = $author.':'.$guid;
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `uri` = '%s' AND `guid` = '%s' LIMIT 1",
@ -954,6 +966,8 @@ function diaspora_store_by_guid($guid, $server, $uid = 0) {
$datarray['tag'] = $str_tags;
$datarray['app'] = $app;
$datarray['visible'] = ((strlen($body)) ? 1 : 0);
$datarray['object'] = $object;
$datarray['object-type'] = $objecttype;
if ($datarray['contact-id'] == 0)
return false;
@ -1001,11 +1015,14 @@ function diaspora_fetch_message($guid, $server, $level = 0) {
$item["guid"] = unxmlify($source_xml->post->status_message->guid);
$item["private"] = (unxmlify($source_xml->post->status_message->public) == 'false');
$item["object"] = json_encode($source_xml->post);
if(strlen($source_xml->post->asphoto->objectId) && ($source_xml->post->asphoto->objectId != 0) && ($source_xml->post->asphoto->image_url)) {
$item["object-type"] = ACTIVITY_OBJ_PHOTO;
$body = '[url=' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '][img]' . notags(unxmlify($source_xml->post->asphoto->objectId)) . '[/img][/url]' . "\n";
$body = scale_external_images($body,false);
} elseif($source_xml->post->asphoto->image_url) {
$item["object-type"] = ACTIVITY_OBJ_PHOTO;
$body = '[img]' . notags(unxmlify($source_xml->post->asphoto->image_url)) . '[/img]' . "\n";
$body = scale_external_images($body);
} elseif($source_xml->post->status_message) {
@ -1015,18 +1032,25 @@ function diaspora_fetch_message($guid, $server, $level = 0) {
if($source_xml->post->status_message->photo->remote_photo_path AND
$source_xml->post->status_message->photo->remote_photo_name) {
$item["object-type"] = ACTIVITY_OBJ_PHOTO;
$remote_photo_path = notags(unxmlify($source_xml->post->status_message->photo->remote_photo_path));
$remote_photo_name = notags(unxmlify($source_xml->post->status_message->photo->remote_photo_name));
$body = '[img]'.$remote_photo_path.$remote_photo_name.'[/img]'."\n".$body;
logger('embedded picture link found: '.$body, LOGGER_DEBUG);
}
} else
$item["object-type"] = ACTIVITY_OBJ_NOTE;
$body = scale_external_images($body);
// Add OEmbed and other information to the body
$body = add_page_info_to_body($body, false, true);
// To-Do: It could be a repeated redmatrix item
// Then we shouldn't add further data to it
if ($item["object-type"] == ACTIVITY_OBJ_NOTE)
$body = add_page_info_to_body($body, false, true);
} elseif($source_xml->post->reshare) {
// Reshare of a reshare
return diaspora_fetch_message($source_xml->post->reshare->root_guid, $server, ++$level);
@ -1105,6 +1129,8 @@ function diaspora_reshare($importer,$xml,$msg) {
$orig_author = $r[0]["author-link"];
$create_original_post = ($body != "");
$orig_url = $a->get_baseurl()."/display/".$orig_guid;
$object = $r[0]["object"];
$objecttype = $r[0]["object-type"];
}
}
@ -1144,6 +1170,8 @@ function diaspora_reshare($importer,$xml,$msg) {
$orig_guid = $item["guid"];
$create_original_post = ($body != "");
$orig_url = $a->get_baseurl()."/display/".$orig_guid;
$object = $item["object"];
$objecttype = $item["object-type"];
}
}
@ -1184,6 +1212,9 @@ function diaspora_reshare($importer,$xml,$msg) {
$datarray['body'] = $body;
}
$datarray["object"] = json_encode($xml);
$datarray['object-type'] = $objecttype;
$datarray['tag'] = $str_tags;
$datarray['app'] = $app;
@ -1210,6 +1241,7 @@ function diaspora_reshare($importer,$xml,$msg) {
$datarray2['owner-link'] = $datarray2['author-link'];
$datarray2['owner-avatar'] = $datarray2['author-avatar'];
$datarray2['body'] = $body;
$datarray2["object"] = $object;
DiasporaFetchGuid($datarray2);
$message_id = item_store($datarray2);
@ -1295,6 +1327,8 @@ function diaspora_asphoto($importer,$xml,$msg) {
$datarray['author-link'] = $contact['url'];
$datarray['author-avatar'] = $contact['thumb'];
$datarray['body'] = $body;
$datarray["object"] = json_encode($xml);
$datarray['object-type'] = ACTIVITY_OBJ_PHOTO;
$datarray['app'] = 'Diaspora/Cubbi.es';
@ -1464,6 +1498,8 @@ function diaspora_comment($importer,$xml,$msg) {
$datarray['author-link'] = $person['url'];
$datarray['author-avatar'] = ((x($person,'thumb')) ? $person['thumb'] : $person['photo']);
$datarray['body'] = $body;
$datarray["object"] = json_encode($xml);
$datarray["object-type"] = ACTIVITY_OBJ_COMMENT;
// We can't be certain what the original app is if the message is relayed.
if(($parent_item['origin']) && (! $parent_author_signature))