|
|
@ -7,6 +7,46 @@ require_once('include/contact_selectors.php'); |
|
|
|
require_once('include/queue_fn.php'); |
|
|
|
require_once('include/lock.php'); |
|
|
|
|
|
|
|
function diaspora_add_page_info($url) { |
|
|
|
require_once("mod/parse_url.php"); |
|
|
|
$data = parseurl_getsiteinfo($url, true); |
|
|
|
|
|
|
|
logger('diaspora_add_page_info: fetch page info for '.$url.' '.print_r($data, true), LOGGER_DATA); |
|
|
|
|
|
|
|
if (($data["type"] != "link") OR ($data["title"] == $url)) |
|
|
|
return(""); |
|
|
|
|
|
|
|
if (is_string($data["title"])) |
|
|
|
$text .= "[bookmark=".$url."]".trim($data["title"])."[/bookmark]"; |
|
|
|
|
|
|
|
if (sizeof($data["images"]) > 0) { |
|
|
|
$imagedata = $data["images"][0]; |
|
|
|
$text .= '[img]'.$imagedata["src"].'[/img]'; |
|
|
|
} |
|
|
|
|
|
|
|
if (is_string($data["text"])) |
|
|
|
$text .= "[quote]".$data["text"]."[/quote]"; |
|
|
|
|
|
|
|
return("\n[class=type-".$data["type"]."]".$text."[/class]"); |
|
|
|
} |
|
|
|
|
|
|
|
function diaspora_add_page_info_to_body($body) { |
|
|
|
|
|
|
|
logger('diaspora_add_page_info_to_body: fetch page info for body '.$body, LOGGER_DATA); |
|
|
|
|
|
|
|
$URLSearchString = "^\[\]"; |
|
|
|
|
|
|
|
// Adding these spaces is a quick hack due to my problems with regular expressions :)
|
|
|
|
preg_match("/[^@#]\[url\]([$URLSearchString]*)\[\/url\]/ism", " ".$body, $matches); |
|
|
|
|
|
|
|
if (!$matches) |
|
|
|
preg_match("/[^@#]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", " ".$body, $matches); |
|
|
|
|
|
|
|
if ($matches) |
|
|
|
$body .= diaspora_add_page_info($matches[1]); |
|
|
|
|
|
|
|
return $body; |
|
|
|
} |
|
|
|
|
|
|
|
function diaspora_dispatch_public($msg) { |
|
|
|
|
|
|
@ -578,7 +618,7 @@ function diaspora_request($importer,$xml) { |
|
|
|
// That makes us friends.
|
|
|
|
|
|
|
|
if($contact['rel'] == CONTACT_IS_FOLLOWER && $importer['page-flags'] != PAGE_COMMUNITY) { |
|
|
|
q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1", |
|
|
|
q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d", |
|
|
|
intval(CONTACT_IS_FRIEND), |
|
|
|
intval($contact['id']), |
|
|
|
intval($importer['uid']) |
|
|
@ -733,7 +773,7 @@ function diaspora_request($importer,$xml) { |
|
|
|
`avatar-date` = '%s', |
|
|
|
`blocked` = 0, |
|
|
|
`pending` = 0 |
|
|
|
WHERE `id` = %d LIMIT 1 |
|
|
|
WHERE `id` = %d |
|
|
|
",
|
|
|
|
dbesc($photos[0]), |
|
|
|
dbesc($photos[1]), |
|
|
@ -759,7 +799,7 @@ function diaspora_post_allow($importer,$contact) { |
|
|
|
// That makes us friends.
|
|
|
|
// Normally this should have handled by getting a request - but this could get lost
|
|
|
|
if($contact['rel'] == CONTACT_IS_FOLLOWER && $importer['page-flags'] != PAGE_COMMUNITY) { |
|
|
|
q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1", |
|
|
|
q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d", |
|
|
|
intval(CONTACT_IS_FRIEND), |
|
|
|
intval($contact['id']), |
|
|
|
intval($importer['uid']) |
|
|
@ -827,6 +867,9 @@ function diaspora_post($importer,$xml,$msg) { |
|
|
|
|
|
|
|
$body = diaspora2bb($xml->raw_message); |
|
|
|
|
|
|
|
// Add OEmbed and other information to the body
|
|
|
|
$body = diaspora_add_page_info_to_body($body); |
|
|
|
|
|
|
|
$datarray = array(); |
|
|
|
|
|
|
|
$str_tags = ''; |
|
|
@ -873,7 +916,7 @@ function diaspora_post($importer,$xml,$msg) { |
|
|
|
$datarray['network'] = NETWORK_DIASPORA; |
|
|
|
$datarray['guid'] = $guid; |
|
|
|
$datarray['uri'] = $datarray['parent-uri'] = $message_id; |
|
|
|
$datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created); |
|
|
|
$datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created); |
|
|
|
$datarray['private'] = $private; |
|
|
|
$datarray['parent'] = 0; |
|
|
|
$datarray['plink'] = $plink; |
|
|
@ -895,7 +938,7 @@ function diaspora_post($importer,$xml,$msg) { |
|
|
|
$message_id = item_store($datarray); |
|
|
|
|
|
|
|
//if($message_id) {
|
|
|
|
// q("update item set plink = '%s' where id = %d limit 1",
|
|
|
|
// q("update item set plink = '%s' where id = %d",
|
|
|
|
// dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
|
|
|
|
// intval($message_id)
|
|
|
|
// );
|
|
|
@ -966,18 +1009,36 @@ function diaspora_reshare($importer,$xml,$msg) { |
|
|
|
} |
|
|
|
elseif($source_xml->post->status_message) { |
|
|
|
$body = diaspora2bb($source_xml->post->status_message->raw_message); |
|
|
|
|
|
|
|
// Checking for embedded pictures
|
|
|
|
if($source_xml->post->status_message->photo->remote_photo_path AND |
|
|
|
$source_xml->post->status_message->photo->remote_photo_name) { |
|
|
|
|
|
|
|
$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('diaspora_reshare: embedded picture link found: '.$body, LOGGER_DEBUG); |
|
|
|
} |
|
|
|
|
|
|
|
$body = scale_external_images($body); |
|
|
|
|
|
|
|
// Add OEmbed and other information to the body
|
|
|
|
$body = diaspora_add_page_info_to_body($body); |
|
|
|
} |
|
|
|
else { |
|
|
|
// Maybe it is a reshare of a photo that will be delivered at a later time (testing)
|
|
|
|
logger('diaspora_reshare: no reshare content found: ' . print_r($source_xml,true)); |
|
|
|
return; |
|
|
|
} |
|
|
|
if(! $body) { |
|
|
|
logger('diaspora_reshare: empty body: source= ' . $x); |
|
|
|
return; |
|
|
|
$body = ""; |
|
|
|
//return;
|
|
|
|
} |
|
|
|
|
|
|
|
//if(! $body) {
|
|
|
|
// logger('diaspora_reshare: empty body: source= ' . $x);
|
|
|
|
// return;
|
|
|
|
//}
|
|
|
|
|
|
|
|
$person = find_diaspora_person_by_handle($orig_author); |
|
|
|
|
|
|
|
/*if(is_array($person) && x($person,'name') && x($person,'url')) |
|
|
@ -1041,7 +1102,7 @@ function diaspora_reshare($importer,$xml,$msg) { |
|
|
|
$datarray['network'] = NETWORK_DIASPORA; |
|
|
|
$datarray['guid'] = $guid; |
|
|
|
$datarray['uri'] = $datarray['parent-uri'] = $message_id; |
|
|
|
$datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created); |
|
|
|
$datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created); |
|
|
|
$datarray['private'] = $private; |
|
|
|
$datarray['parent'] = 0; |
|
|
|
$datarray['plink'] = $plink; |
|
|
@ -1068,10 +1129,13 @@ function diaspora_reshare($importer,$xml,$msg) { |
|
|
|
$datarray['tag'] = $str_tags; |
|
|
|
$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. (testing)
|
|
|
|
$datarray['visible'] = ((strlen($body)) ? 1 : 0); |
|
|
|
|
|
|
|
$message_id = item_store($datarray); |
|
|
|
|
|
|
|
//if($message_id) {
|
|
|
|
// q("update item set plink = '%s' where id = %d limit 1",
|
|
|
|
// q("update item set plink = '%s' where id = %d",
|
|
|
|
// dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
|
|
|
|
// intval($message_id)
|
|
|
|
// );
|
|
|
@ -1152,7 +1216,7 @@ function diaspora_asphoto($importer,$xml,$msg) { |
|
|
|
$datarray['network'] = NETWORK_DIASPORA; |
|
|
|
$datarray['guid'] = $guid; |
|
|
|
$datarray['uri'] = $datarray['parent-uri'] = $message_id; |
|
|
|
$datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created); |
|
|
|
$datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert('UTC','UTC',$created); |
|
|
|
$datarray['private'] = $private; |
|
|
|
$datarray['parent'] = 0; |
|
|
|
$datarray['plink'] = $plink; |
|
|
@ -1170,7 +1234,7 @@ function diaspora_asphoto($importer,$xml,$msg) { |
|
|
|
$message_id = item_store($datarray); |
|
|
|
|
|
|
|
//if($message_id) {
|
|
|
|
// q("update item set plink = '%s' where id = %d limit 1",
|
|
|
|
// q("update item set plink = '%s' where id = %d",
|
|
|
|
// dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id),
|
|
|
|
// intval($message_id)
|
|
|
|
// );
|
|
|
@ -1277,7 +1341,7 @@ function diaspora_comment($importer,$xml,$msg) { |
|
|
|
if(strcasecmp($diaspora_handle,$msg['author']) == 0) |
|
|
|
$person = $contact; |
|
|
|
else { |
|
|
|
$person = find_diaspora_person_by_handle($diaspora_handle); |
|
|
|
$person = find_diaspora_person_by_handle($diaspora_handle); |
|
|
|
|
|
|
|
if(! is_array($person)) { |
|
|
|
logger('diaspora_comment: unable to find author details'); |
|
|
@ -1286,7 +1350,6 @@ function diaspora_comment($importer,$xml,$msg) { |
|
|
|
} |
|
|
|
|
|
|
|
$body = diaspora2bb($text); |
|
|
|
|
|
|
|
$message_id = $diaspora_handle . ':' . $guid; |
|
|
|
|
|
|
|
$datarray = array(); |
|
|
@ -1330,7 +1393,7 @@ function diaspora_comment($importer,$xml,$msg) { |
|
|
|
$datarray['parent-uri'] = $parent_item['uri']; |
|
|
|
|
|
|
|
// No timestamps for comments? OK, we'll the use current time.
|
|
|
|
$datarray['created'] = $datarray['edited'] = datetime_convert(); |
|
|
|
$datarray['changed'] = $datarray['created'] = $datarray['edited'] = datetime_convert(); |
|
|
|
$datarray['private'] = $parent_item['private']; |
|
|
|
|
|
|
|
$datarray['owner-name'] = $parent_item['owner-name']; |
|
|
@ -1350,7 +1413,7 @@ function diaspora_comment($importer,$xml,$msg) { |
|
|
|
$message_id = item_store($datarray); |
|
|
|
|
|
|
|
if($message_id) { |
|
|
|
q("update item set plink = '%s' where id = %d limit 1", |
|
|
|
q("update item set plink = '%s' where id = %d", |
|
|
|
dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), |
|
|
|
intval($message_id) |
|
|
|
); |
|
|
@ -1559,15 +1622,15 @@ function diaspora_conversation($importer,$xml,$msg) { |
|
|
|
dbesc($message_id), |
|
|
|
dbesc($parent_uri), |
|
|
|
dbesc($msg_created_at) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
q("update conv set updated = '%s' where id = %d limit 1", |
|
|
|
q("update conv set updated = '%s' where id = %d", |
|
|
|
dbesc(datetime_convert()), |
|
|
|
intval($conversation['id']) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
require_once('include/enotify.php'); |
|
|
|
notification(array( |
|
|
|
notification(array( |
|
|
|
'type' => NOTIFY_MAIL, |
|
|
|
'notify_flags' => $importer['notify-flags'], |
|
|
|
'language' => $importer['language'], |
|
|
@ -1626,7 +1689,7 @@ function diaspora_message($importer,$xml,$msg) { |
|
|
|
} |
|
|
|
|
|
|
|
$reply = 0; |
|
|
|
|
|
|
|
|
|
|
|
$body = diaspora2bb($msg_text); |
|
|
|
$message_id = $msg_diaspora_handle . ':' . $msg_guid; |
|
|
|
|
|
|
@ -1672,13 +1735,13 @@ function diaspora_message($importer,$xml,$msg) { |
|
|
|
dbesc($message_id), |
|
|
|
dbesc($parent_uri), |
|
|
|
dbesc($msg_created_at) |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
q("update conv set updated = '%s' where id = %d limit 1", |
|
|
|
q("update conv set updated = '%s' where id = %d", |
|
|
|
dbesc(datetime_convert()), |
|
|
|
intval($conversation['id']) |
|
|
|
); |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
@ -1740,7 +1803,7 @@ function diaspora_photo($importer,$xml,$msg,$attempt=1) { |
|
|
|
array($remote_photo_name, 'scaled_full_' . $remote_photo_name)); |
|
|
|
|
|
|
|
if(strpos($parent_item['body'],$link_text) === false) { |
|
|
|
$r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d limit 1", |
|
|
|
$r = q("update item set `body` = '%s', `visible` = 1 where `id` = %d and `uid` = %d", |
|
|
|
dbesc($link_text . $parent_item['body']), |
|
|
|
intval($parent_item['id']), |
|
|
|
intval($parent_item['uid']) |
|
|
@ -1800,12 +1863,12 @@ function diaspora_like($importer,$xml,$msg) { |
|
|
|
if($positive === 'true') { |
|
|
|
logger('diaspora_like: duplicate like: ' . $guid); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// Note: I don't think "Like" objects with positive = "false" are ever actually used
|
|
|
|
// It looks like "RelayableRetractions" are used for "unlike" instead
|
|
|
|
if($positive === 'false') { |
|
|
|
logger('diaspora_like: received a like with positive set to "false"...ignoring'); |
|
|
|
/* q("UPDATE `item` SET `deleted` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1", |
|
|
|
/* q("UPDATE `item` SET `deleted` = 1 WHERE `id` = %d AND `uid` = %d", |
|
|
|
intval($r[0]['id']), |
|
|
|
intval($importer['uid']) |
|
|
|
);*/ |
|
|
@ -1942,7 +2005,7 @@ EOT; |
|
|
|
|
|
|
|
|
|
|
|
if($message_id) { |
|
|
|
q("update item set plink = '%s' where id = %d limit 1", |
|
|
|
q("update item set plink = '%s' where id = %d", |
|
|
|
dbesc($a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $message_id), |
|
|
|
intval($message_id) |
|
|
|
); |
|
|
@ -1989,8 +2052,8 @@ function diaspora_retraction($importer,$xml) { |
|
|
|
); |
|
|
|
if(count($r)) { |
|
|
|
if(link_compare($r[0]['author-link'],$contact['url'])) { |
|
|
|
q("update item set `deleted` = 1, `changed` = '%s' where `id` = %d limit 1", |
|
|
|
dbesc(datetime_convert()), |
|
|
|
q("update item set `deleted` = 1, `changed` = '%s' where `id` = %d", |
|
|
|
dbesc(datetime_convert()), |
|
|
|
intval($r[0]['id']) |
|
|
|
); |
|
|
|
} |
|
|
@ -2060,12 +2123,12 @@ function diaspora_signed_retraction($importer,$xml,$msg) { |
|
|
|
); |
|
|
|
if(count($r)) { |
|
|
|
if(link_compare($r[0]['author-link'],$contact['url'])) { |
|
|
|
q("update item set `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '' , `title` = '' where `id` = %d limit 1", |
|
|
|
dbesc(datetime_convert()), |
|
|
|
dbesc(datetime_convert()), |
|
|
|
q("update item set `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '' , `title` = '' where `id` = %d", |
|
|
|
dbesc(datetime_convert()), |
|
|
|
dbesc(datetime_convert()), |
|
|
|
intval($r[0]['id']) |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// Now check if the retraction needs to be relayed by us
|
|
|
|
//
|
|
|
|
// The first item in the `item` table with the parent id is the parent. However, MySQL doesn't always
|
|
|
@ -2161,7 +2224,7 @@ function diaspora_profile($importer,$xml,$msg) { |
|
|
|
// TODO: update name on item['author-name'] if the name changed. See consume_feed()
|
|
|
|
// Not doing this currently because D* protocol is scheduled for revision soon.
|
|
|
|
|
|
|
|
$r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", |
|
|
|
$r = q("UPDATE `contact` SET `name` = '%s', `name-date` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' , `bd` = '%s' WHERE `id` = %d AND `uid` = %d", |
|
|
|
dbesc($name), |
|
|
|
dbesc(datetime_convert()), |
|
|
|
dbesc($images[0]), |
|
|
@ -2331,7 +2394,7 @@ function diaspora_send_images($item,$owner,$contact,$images,$public_batch = fals |
|
|
|
if(! count($r)) |
|
|
|
continue; |
|
|
|
$public = (($r[0]['allow_cid'] || $r[0]['allow_gid'] || $r[0]['deny_cid'] || $r[0]['deny_gid']) ? 'false' : 'true' ); |
|
|
|
$msg = replace_macros($tpl,array( |
|
|
|
$msg = replace_macros($tpl,array( |
|
|
|
'$path' => xmlify($image['path']), |
|
|
|
'$filename' => xmlify($image['file']), |
|
|
|
'$msg_guid' => xmlify($image['guid']), |
|
|
|