Merge remote-tracking branch 'upstream/develop' into develop

Signed-off-by: Roland Häder <roland@mxchange.org>

Conflicts:
	include/diaspora.php
	object/Item.php
This commit is contained in:
Roland Häder 2016-12-22 11:29:56 +01:00
commit c0df692f5f
16 changed files with 176 additions and 87 deletions

View file

@ -106,7 +106,7 @@ function terminate_friendship($user,$self,$contact) {
} }
elseif($contact['network'] === NETWORK_DIASPORA) { elseif($contact['network'] === NETWORK_DIASPORA) {
require_once('include/diaspora.php'); require_once('include/diaspora.php');
diaspora::send_unshare($user,$contact); Diaspora::send_unshare($user,$contact);
} }
elseif($contact['network'] === NETWORK_DFRN) { elseif($contact['network'] === NETWORK_DFRN) {
require_once('include/dfrn.php'); require_once('include/dfrn.php');

View file

@ -3218,7 +3218,7 @@
function api_share_as_retweet(&$item) { function api_share_as_retweet(&$item) {
$body = trim($item["body"]); $body = trim($item["body"]);
if (diaspora::is_reshare($body, false)===false) { if (Diaspora::is_reshare($body, false)===false) {
return false; return false;
} }

View file

@ -99,7 +99,7 @@ function network_to_name($s, $profile = "") {
$networkname = str_replace($search,$replace,$s); $networkname = str_replace($search,$replace,$s);
if (($s == NETWORK_DIASPORA) AND ($profile != "") AND diaspora::is_redmatrix($profile)) { if (($s == NETWORK_DIASPORA) AND ($profile != "") AND Diaspora::is_redmatrix($profile)) {
$networkname = t("Hubzilla/Redmatrix"); $networkname = t("Hubzilla/Redmatrix");
$r = q("SELECT `gserver`.`platform` FROM `gcontact` $r = q("SELECT `gserver`.`platform` FROM `gcontact`

View file

@ -508,7 +508,7 @@ function delivery_run(&$argv, &$argc){
break; break;
if ($mail) { if ($mail) {
diaspora::send_mail($item,$owner,$contact); Diaspora::send_mail($item,$owner,$contact);
break; break;
} }
@ -530,22 +530,22 @@ function delivery_run(&$argv, &$argc){
if (($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) { if (($target_item['deleted']) && (($target_item['uri'] === $target_item['parent-uri']) || $followup)) {
// top-level retraction // top-level retraction
logger('diaspora retract: '.$loc); logger('diaspora retract: '.$loc);
diaspora::send_retraction($target_item,$owner,$contact,$public_message); Diaspora::send_retraction($target_item,$owner,$contact,$public_message);
break; break;
} elseif ($followup) { } elseif ($followup) {
// send comments and likes to owner to relay // send comments and likes to owner to relay
logger('diaspora followup: '.$loc); logger('diaspora followup: '.$loc);
diaspora::send_followup($target_item,$owner,$contact,$public_message); Diaspora::send_followup($target_item,$owner,$contact,$public_message);
break; break;
} elseif ($target_item['uri'] !== $target_item['parent-uri']) { } elseif ($target_item['uri'] !== $target_item['parent-uri']) {
// we are the relay - send comments, likes and relayable_retractions to our conversants // we are the relay - send comments, likes and relayable_retractions to our conversants
logger('diaspora relay: '.$loc); logger('diaspora relay: '.$loc);
diaspora::send_relay($target_item,$owner,$contact,$public_message); Diaspora::send_relay($target_item,$owner,$contact,$public_message);
break; break;
} elseif ($top_level && !$walltowall) { } elseif ($top_level && !$walltowall) {
// currently no workable solution for sending walltowall // currently no workable solution for sending walltowall
logger('diaspora status: '.$loc); logger('diaspora status: '.$loc);
diaspora::send_status($target_item,$owner,$contact,$public_message); Diaspora::send_status($target_item,$owner,$contact,$public_message);
break; break;
} }

View file

@ -23,7 +23,7 @@ require_once("include/queue_fn.php");
* @brief This class contain functions to create and send Diaspora XML files * @brief This class contain functions to create and send Diaspora XML files
* *
*/ */
class diaspora { class Diaspora {
/** /**
* @brief Return a list of relay servers * @brief Return a list of relay servers
@ -344,7 +344,7 @@ class diaspora {
// This will often be different with relayed messages (for example "like" and "comment") // This will often be different with relayed messages (for example "like" and "comment")
$sender = $msg["author"]; $sender = $msg["author"];
if (!diaspora::valid_posting($msg, $fields)) { if (!self::valid_posting($msg, $fields)) {
logger("Invalid posting"); logger("Invalid posting");
return false; return false;
} }
@ -669,27 +669,30 @@ class diaspora {
* @return string the handle * @return string the handle
*/ */
public static function handle_from_contact($contact_id, $gcontact_id = 0) { public static function handle_from_contact($contact_id, $gcontact_id = 0) {
$handle = False; $handle = false;
logger("contact id is ".$contact_id." - gcontact id is ".$gcontact_id, LOGGER_DEBUG); logger("contact id is ".$contact_id." - gcontact id is ".$gcontact_id, LOGGER_DEBUG);
if ($gcontact_id != 0) { if ($gcontact_id != 0) {
$r = q("SELECT `addr` FROM `gcontact` WHERE `id` = %d AND `addr` != ''", $r = q("SELECT `addr` FROM `gcontact` WHERE `id` = %d AND `addr` != ''",
intval($gcontact_id)); intval($gcontact_id));
if ($r)
if (dbm::is_result($r)) {
return strtolower($r[0]["addr"]); return strtolower($r[0]["addr"]);
}
} }
$r = q("SELECT `network`, `addr`, `self`, `url`, `nick` FROM `contact` WHERE `id` = %d", $r = q("SELECT `network`, `addr`, `self`, `url`, `nick` FROM `contact` WHERE `id` = %d",
intval($contact_id)); intval($contact_id));
if ($r) {
if (dbm::is_result($r)) {
$contact = $r[0]; $contact = $r[0];
logger("contact 'self' = ".$contact['self']." 'url' = ".$contact['url'], LOGGER_DEBUG); logger("contact 'self' = ".$contact['self']." 'url' = ".$contact['url'], LOGGER_DEBUG);
if($contact['addr'] != "") if ($contact['addr'] != "") {
$handle = $contact['addr']; $handle = $contact['addr'];
else { } else {
$baseurl_start = strpos($contact['url'],'://') + 3; $baseurl_start = strpos($contact['url'],'://') + 3;
$baseurl_length = strpos($contact['url'],'/profile') - $baseurl_start; // allows installations in a subdirectory--not sure how Diaspora will handle $baseurl_length = strpos($contact['url'],'/profile') - $baseurl_start; // allows installations in a subdirectory--not sure how Diaspora will handle
$baseurl = substr($contact['url'], $baseurl_start, $baseurl_length); $baseurl = substr($contact['url'], $baseurl_start, $baseurl_length);
@ -700,6 +703,29 @@ class diaspora {
return strtolower($handle); return strtolower($handle);
} }
/**
* @brief get a url (scheme://domain.tld/u/user) from a given Diaspora*
* fcontact guid
*
* @param mixed $fcontact_guid Hexadecimal string guid
*
* @return string the contact url or null
*/
public static function url_from_contact_guid($fcontact_guid) {
logger("fcontact guid is ".$fcontact_guid, LOGGER_DEBUG);
$r = q("SELECT `url` FROM `fcontact` WHERE `url` != '' AND `network` = '%s' AND `guid` = '%s'",
dbesc(NETWORK_DIASPORA),
dbesc($fcontact_guid)
);
if (dbm::is_result($r)) {
return $r[0]['url'];
}
return null;
}
/** /**
* @brief Get a contact id for a given handle * @brief Get a contact id for a given handle
* *
@ -826,6 +852,38 @@ class diaspora {
},$item["body"]); },$item["body"]);
} }
/**
* @brief Checks for relative /people/* links in an item body to match local
* contacts or prepends the remote host taken from the author link.
*
* @param string $body The item body to replace links from
* @param string $author_link The author link for missing local contact fallback
*
* @return the replaced string
*/
public function replace_people_guid($body, $author_link) {
$return = preg_replace_callback("&\[url=/people/([^\[\]]*)\](.*)\[\/url\]&Usi",
function ($match) use ($author_link) {
// $match
// 0 => '[url=/people/0123456789abcdef]Foo Bar[/url]'
// 1 => '0123456789abcdef'
// 2 => 'Foo Bar'
$handle = self::url_from_contact_guid($match[1]);
if ($handle) {
$return = '@[url='.$handle.']'.$match[2].'[/url]';
} else {
// No local match, restoring absolute remote URL from author scheme and host
$author_url = parse_url($author_link);
$return = '[url='.$author_url['scheme'].'://'.$author_url['host'].'/people/'.$match[1].']'.$match[2].'[/url]';
}
return $return;
}, $body);
return $return;
}
/** /**
* @brief sub function of "fetch_guid" which checks for links in messages * @brief sub function of "fetch_guid" which checks for links in messages
* *
@ -1115,22 +1173,26 @@ class diaspora {
$text = unxmlify($data->text); $text = unxmlify($data->text);
$author = notags(unxmlify($data->author)); $author = notags(unxmlify($data->author));
if (isset($data->created_at)) if (isset($data->created_at)) {
$created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at))); $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
else } else {
$created_at = datetime_convert(); $created_at = datetime_convert();
}
$contact = self::allowed_contact_by_handle($importer, $sender, true); $contact = self::allowed_contact_by_handle($importer, $sender, true);
if (!$contact) if (!$contact) {
return false; return false;
}
$message_id = self::message_exists($importer["uid"], $guid); $message_id = self::message_exists($importer["uid"], $guid);
if ($message_id) if ($message_id) {
return $message_id; return $message_id;
}
$parent_item = self::parent_item($importer["uid"], $parent_guid, $author, $contact); $parent_item = self::parent_item($importer["uid"], $parent_guid, $author, $contact);
if (!$parent_item) if (!$parent_item) {
return false; return false;
}
$person = self::person_by_handle($author); $person = self::person_by_handle($author);
if (!is_array($person)) { if (!is_array($person)) {
@ -1168,14 +1230,17 @@ class diaspora {
$datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at; $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at;
$datarray["body"] = diaspora2bb($text); $body = diaspora2bb($text);
$datarray["body"] = self::replace_people_guid($body, $person["url"]);
self::fetch_guid($datarray); self::fetch_guid($datarray);
$message_id = item_store($datarray); $message_id = item_store($datarray);
if ($message_id) if ($message_id) {
logger("Stored comment ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG); logger("Stored comment ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG);
}
// If we are the origin of the parent we store the original data and notify our followers // If we are the origin of the parent we store the original data and notify our followers
if($message_id AND $parent_item["origin"]) { if($message_id AND $parent_item["origin"]) {
@ -1211,8 +1276,6 @@ class diaspora {
$subject = notags(unxmlify($data->subject)); $subject = notags(unxmlify($data->subject));
$author = notags(unxmlify($data->author)); $author = notags(unxmlify($data->author));
$reply = 0;
$msg_guid = notags(unxmlify($mesg->guid)); $msg_guid = notags(unxmlify($mesg->guid));
$msg_parent_guid = notags(unxmlify($mesg->parent_guid)); $msg_parent_guid = notags(unxmlify($mesg->parent_guid));
$msg_parent_author_signature = notags(unxmlify($mesg->parent_author_signature)); $msg_parent_author_signature = notags(unxmlify($mesg->parent_author_signature));
@ -1222,16 +1285,17 @@ class diaspora {
// "diaspora_handle" is the element name from the old version // "diaspora_handle" is the element name from the old version
// "author" is the element name from the new version // "author" is the element name from the new version
if ($mesg->author) if ($mesg->author) {
$msg_author = notags(unxmlify($mesg->author)); $msg_author = notags(unxmlify($mesg->author));
elseif ($mesg->diaspora_handle) } elseif ($mesg->diaspora_handle) {
$msg_author = notags(unxmlify($mesg->diaspora_handle)); $msg_author = notags(unxmlify($mesg->diaspora_handle));
else } else {
return false; return false;
}
$msg_conversation_guid = notags(unxmlify($mesg->conversation_guid)); $msg_conversation_guid = notags(unxmlify($mesg->conversation_guid));
if($msg_conversation_guid != $guid) { if ($msg_conversation_guid != $guid) {
logger("message conversation guid does not belong to the current conversation."); logger("message conversation guid does not belong to the current conversation.");
return false; return false;
} }
@ -1243,15 +1307,15 @@ class diaspora {
$author_signature = base64_decode($msg_author_signature); $author_signature = base64_decode($msg_author_signature);
if(strcasecmp($msg_author,$msg["author"]) == 0) { if (strcasecmp($msg_author,$msg["author"]) == 0) {
$person = $contact; $person = $contact;
$key = $msg["key"]; $key = $msg["key"];
} else { } else {
$person = self::person_by_handle($msg_author); $person = self::person_by_handle($msg_author);
if (is_array($person) && x($person, "pubkey")) if (is_array($person) && x($person, "pubkey")) {
$key = $person["pubkey"]; $key = $person["pubkey"];
else { } else {
logger("unable to find author details"); logger("unable to find author details");
return false; return false;
} }
@ -1262,7 +1326,7 @@ class diaspora {
return false; return false;
} }
if($msg_parent_author_signature) { if ($msg_parent_author_signature) {
$owner_signed_data = $msg_guid.";".$msg_parent_guid.";".$msg_text.";".unxmlify($mesg->created_at).";".$msg_author.";".$msg_conversation_guid; $owner_signed_data = $msg_guid.";".$msg_parent_guid.";".$msg_text.";".unxmlify($mesg->created_at).";".$msg_author.";".$msg_conversation_guid;
$parent_author_signature = base64_decode($msg_parent_author_signature); $parent_author_signature = base64_decode($msg_parent_author_signature);
@ -1546,8 +1610,9 @@ class diaspora {
$conversation_guid = notags(unxmlify($data->conversation_guid)); $conversation_guid = notags(unxmlify($data->conversation_guid));
$contact = self::allowed_contact_by_handle($importer, $author, true); $contact = self::allowed_contact_by_handle($importer, $author, true);
if (!$contact) if (!$contact) {
return false; return false;
}
$conversation = null; $conversation = null;
@ -1555,16 +1620,13 @@ class diaspora {
intval($importer["uid"]), intval($importer["uid"]),
dbesc($conversation_guid) dbesc($conversation_guid)
); );
if($c) if ($c) {
$conversation = $c[0]; $conversation = $c[0];
else { } else {
logger("conversation not available."); logger("conversation not available.");
return false; return false;
} }
$reply = 0;
$body = diaspora2bb($text);
$message_uri = $author.":".$guid; $message_uri = $author.":".$guid;
$person = self::person_by_handle($author); $person = self::person_by_handle($author);
@ -1577,11 +1639,15 @@ class diaspora {
dbesc($message_uri), dbesc($message_uri),
intval($importer["uid"]) intval($importer["uid"])
); );
if ($r) { if (dbm::is_result($r)) {
logger("duplicate message already delivered.", LOGGER_DEBUG); logger("duplicate message already delivered.", LOGGER_DEBUG);
return false; return false;
} }
$body = diaspora2bb($text);
$body = self::replace_people_guid($body, $person["url"]);
q("INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`) q("INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`)
VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')", VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
intval($importer["uid"]), intval($importer["uid"]),
@ -2022,26 +2088,29 @@ class diaspora {
FROM `item` WHERE `guid` = '%s' AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1", FROM `item` WHERE `guid` = '%s' AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1",
dbesc($guid)); dbesc($guid));
if ($r) { if (dbm::is_result($r)) {
logger("reshared message ".$guid." already exists on system."); logger("reshared message ".$guid." already exists on system.");
// Maybe it is already a reshared item? // Maybe it is already a reshared item?
// Then refetch the content, if it is a reshare from a reshare. // Then refetch the content, if it is a reshare from a reshare.
// If it is a reshared post from another network then reformat to avoid display problems with two share elements // If it is a reshared post from another network then reformat to avoid display problems with two share elements
if (self::is_reshare($r[0]["body"], true)) if (self::is_reshare($r[0]["body"], true)) {
$r = array(); $r = array();
elseif (self::is_reshare($r[0]["body"], false)) { } elseif (self::is_reshare($r[0]["body"], false)) {
$r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"])); $r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"]));
$r[0]["body"] = self::replace_people_guid($r[0]["body"], $r[0]["author-link"]);
// Add OEmbed and other information to the body // Add OEmbed and other information to the body
$r[0]["body"] = add_page_info_to_body($r[0]["body"], false, true); $r[0]["body"] = add_page_info_to_body($r[0]["body"], false, true);
return $r[0]; return $r[0];
} else } else {
return $r[0]; return $r[0];
}
} }
if (!$r) { if (!dbm::is_result($r)) {
$server = "https://".substr($orig_author, strpos($orig_author, "@") + 1); $server = "https://".substr($orig_author, strpos($orig_author, "@") + 1);
logger("1st try: reshared message ".$guid." will be fetched via SSL from the server ".$server); logger("1st try: reshared message ".$guid." will be fetched via SSL from the server ".$server);
$item_id = self::store_by_guid($guid, $server); $item_id = self::store_by_guid($guid, $server);
@ -2058,10 +2127,12 @@ class diaspora {
FROM `item` WHERE `id` = %d AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1", FROM `item` WHERE `id` = %d AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1",
intval($item_id)); intval($item_id));
if ($r) { if (dbm::is_result($r)) {
// If it is a reshared post from another network then reformat to avoid display problems with two share elements // If it is a reshared post from another network then reformat to avoid display problems with two share elements
if (self::is_reshare($r[0]["body"], false)) if (self::is_reshare($r[0]["body"], false)) {
$r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"])); $r[0]["body"] = diaspora2bb(bb2diaspora($r[0]["body"]));
$r[0]["body"] = self::replace_people_guid($r[0]["body"], $r[0]["author-link"]);
}
return $r[0]; return $r[0];
} }
@ -2089,16 +2160,19 @@ class diaspora {
$created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at))); $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
$contact = self::allowed_contact_by_handle($importer, $author, false); $contact = self::allowed_contact_by_handle($importer, $author, false);
if (!$contact) if (!$contact) {
return false; return false;
}
$message_id = self::message_exists($importer["uid"], $guid); $message_id = self::message_exists($importer["uid"], $guid);
if ($message_id) if ($message_id) {
return $message_id; return $message_id;
}
$original_item = self::original_item($root_guid, $root_author, $author); $original_item = self::original_item($root_guid, $root_author, $author);
if (!$original_item) if (!$original_item) {
return false; return false;
}
$orig_url = App::get_baseurl()."/display/".$original_item["guid"]; $orig_url = App::get_baseurl()."/display/".$original_item["guid"];
@ -2140,8 +2214,9 @@ class diaspora {
self::fetch_guid($datarray); self::fetch_guid($datarray);
$message_id = item_store($datarray); $message_id = item_store($datarray);
if ($message_id) if ($message_id) {
logger("Stored reshare ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG); logger("Stored reshare ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG);
}
return $message_id; return $message_id;
} }
@ -2170,8 +2245,9 @@ class diaspora {
dbesc($target_guid), dbesc($target_guid),
intval($importer["uid"]) intval($importer["uid"])
); );
if (!$r) if (!$r) {
return false; return false;
}
// Check if the sender is the thread owner // Check if the sender is the thread owner
$p = q("SELECT `id`, `author-link`, `origin` FROM `item` WHERE `id` = %d", $p = q("SELECT `id`, `author-link`, `origin` FROM `item` WHERE `id` = %d",
@ -2194,7 +2270,7 @@ class diaspora {
logger("Deleted target ".$target_guid." (".$r[0]["id"].") from user ".$importer["uid"]." parent: ".$p[0]["id"], LOGGER_DEBUG); logger("Deleted target ".$target_guid." (".$r[0]["id"].") from user ".$importer["uid"]." parent: ".$p[0]["id"], LOGGER_DEBUG);
// Now check if the retraction needs to be relayed by us // Now check if the retraction needs to be relayed by us
if($p[0]["origin"]) { if ($p[0]["origin"]) {
// notify others // notify others
proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $r[0]["id"]); proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $r[0]["id"]);
} }
@ -2268,17 +2344,21 @@ class diaspora {
// die("poll!\n"); // die("poll!\n");
//} //}
$contact = self::allowed_contact_by_handle($importer, $author, false); $contact = self::allowed_contact_by_handle($importer, $author, false);
if (!$contact) if (!$contact) {
return false; return false;
}
$message_id = self::message_exists($importer["uid"], $guid); $message_id = self::message_exists($importer["uid"], $guid);
if ($message_id) if ($message_id) {
return $message_id; return $message_id;
}
$address = array(); $address = array();
if ($data->location) if ($data->location) {
foreach ($data->location->children() AS $fieldname => $data) foreach ($data->location->children() AS $fieldname => $data) {
$address[$fieldname] = notags(unxmlify($data)); $address[$fieldname] = notags(unxmlify($data));
}
}
$body = diaspora2bb($raw_message); $body = diaspora2bb($raw_message);
@ -2286,17 +2366,19 @@ class diaspora {
// Attach embedded pictures to the body // Attach embedded pictures to the body
if ($data->photo) { if ($data->photo) {
foreach ($data->photo AS $photo) foreach ($data->photo AS $photo) {
$body = "[img]".unxmlify($photo->remote_photo_path). $body = "[img]".unxmlify($photo->remote_photo_path).
unxmlify($photo->remote_photo_name)."[/img]\n".$body; unxmlify($photo->remote_photo_name)."[/img]\n".$body;
}
$datarray["object-type"] = ACTIVITY_OBJ_IMAGE; $datarray["object-type"] = ACTIVITY_OBJ_IMAGE;
} else { } else {
$datarray["object-type"] = ACTIVITY_OBJ_NOTE; $datarray["object-type"] = ACTIVITY_OBJ_NOTE;
// Add OEmbed and other information to the body // Add OEmbed and other information to the body
if (!self::is_redmatrix($contact["url"])) if (!self::is_redmatrix($contact["url"])) {
$body = add_page_info_to_body($body, false, true); $body = add_page_info_to_body($body, false, true);
}
} }
$datarray["uid"] = $importer["uid"]; $datarray["uid"] = $importer["uid"];
@ -2319,26 +2401,30 @@ class diaspora {
$datarray["object"] = $xml; $datarray["object"] = $xml;
$datarray["body"] = $body; $datarray["body"] = self::replace_people_guid($body, $contact["url"]);
if ($provider_display_name != "") if ($provider_display_name != "") {
$datarray["app"] = $provider_display_name; $datarray["app"] = $provider_display_name;
}
$datarray["plink"] = self::plink($author, $guid); $datarray["plink"] = self::plink($author, $guid);
$datarray["private"] = (($public == "false") ? 1 : 0); $datarray["private"] = (($public == "false") ? 1 : 0);
$datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at; $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at;
if (isset($address["address"])) if (isset($address["address"])) {
$datarray["location"] = $address["address"]; $datarray["location"] = $address["address"];
}
if (isset($address["lat"]) AND isset($address["lng"])) if (isset($address["lat"]) AND isset($address["lng"])) {
$datarray["coord"] = $address["lat"]." ".$address["lng"]; $datarray["coord"] = $address["lat"]." ".$address["lng"];
}
self::fetch_guid($datarray); self::fetch_guid($datarray);
$message_id = item_store($datarray); $message_id = item_store($datarray);
if ($message_id) if ($message_id) {
logger("Stored item ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG); logger("Stored item ".$datarray["guid"]." with message id ".$message_id, LOGGER_DEBUG);
}
return $message_id; return $message_id;
} }
@ -2355,15 +2441,17 @@ class diaspora {
* @return string the handle in the format user@domain.tld * @return string the handle in the format user@domain.tld
*/ */
private function my_handle($contact) { private function my_handle($contact) {
if ($contact["addr"] != "") if ($contact["addr"] != "") {
return $contact["addr"]; return $contact["addr"];
}
// Normally we should have a filled "addr" field - but in the past this wasn't the case // Normally we should have a filled "addr" field - but in the past this wasn't the case
// So - just in case - we build the the address here. // So - just in case - we build the the address here.
if ($contact["nickname"] != "") if ($contact["nickname"] != "") {
$nick = $contact["nickname"]; $nick = $contact["nickname"];
else } else {
$nick = $contact["nick"]; $nick = $contact["nick"];
}
return $nick."@".substr(App::get_baseurl(), strpos(App::get_baseurl(),"://") + 3); return $nick."@".substr(App::get_baseurl(), strpos(App::get_baseurl(),"://") + 3);
} }
@ -2382,7 +2470,7 @@ class diaspora {
$b64url_data = base64url_encode($msg); $b64url_data = base64url_encode($msg);
$data = str_replace(array("\n", "\r", " ", "\t"), array("", "", "", ""), $b64url_data); $data = str_replace(array("\n", "\r", " ", "\t"), array("", "", "", ""), $b64url_data);
$key_id = base64url_encode(diaspora::my_handle($user)); $key_id = base64url_encode(self::my_handle($user));
$type = "application/xml"; $type = "application/xml";
$encoding = "base64url"; $encoding = "base64url";
$alg = "RSA-SHA256"; $alg = "RSA-SHA256";
@ -2908,7 +2996,7 @@ class diaspora {
*/ */
public static function send_status($item, $owner, $contact, $public_batch = false) { public static function send_status($item, $owner, $contact, $public_batch = false) {
$status = diaspora::build_status($item, $owner); $status = self::build_status($item, $owner);
return self::build_and_transmit($owner, $contact, $status["type"], $status["message"], $public_batch, $item["guid"]); return self::build_and_transmit($owner, $contact, $status["type"], $status["message"], $public_batch, $item["guid"]);
} }

View file

@ -293,8 +293,9 @@ function new_contact($uid,$url,$interactive = false) {
$slap = ostatus::salmon($item, $r[0]); $slap = ostatus::salmon($item, $r[0]);
slapper($r[0], $contact['notify'], $slap); slapper($r[0], $contact['notify'], $slap);
} }
if ($contact['network'] == NETWORK_DIASPORA) { if ($contact['network'] == NETWORK_DIASPORA) {
$ret = diaspora::send_share($a->user,$contact); $ret = Diaspora::send_share($a->user,$contact);
logger('share returns: '.$ret); logger('share returns: '.$ret);
} }
} }

View file

@ -246,7 +246,7 @@ EOT;
// Save the author information for the like in case we need to relay to Diaspora // Save the author information for the like in case we need to relay to Diaspora
diaspora::store_like_signature($contact, $post_id); Diaspora::store_like_signature($contact, $post_id);
$arr['id'] = $post_id; $arr['id'] = $post_id;

View file

@ -571,7 +571,7 @@ function notifier_run(&$argv, &$argc){
if($public_message) { if($public_message) {
if (!$followup) if (!$followup)
$r0 = diaspora::relay_list(); $r0 = Diaspora::relay_list();
else else
$r0 = array(); $r0 = array();

View file

@ -2,5 +2,5 @@
require_once('include/diaspora.php'); require_once('include/diaspora.php');
function profile_change() { function profile_change() {
diaspora::send_profile(local_user()); Diaspora::send_profile(local_user());
} }

View file

@ -196,7 +196,7 @@ function queue_run(&$argv, &$argc){
case NETWORK_DIASPORA: case NETWORK_DIASPORA:
if($contact['notify']) { if($contact['notify']) {
logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>'); logger('queue: diaspora_delivery: item '.$q_item['id'].' for '.$contact['name'].' <'.$contact['url'].'>');
$deliver_status = diaspora::transmit($owner,$contact,$data,$public,true); $deliver_status = Diaspora::transmit($owner,$contact,$data,$public,true);
if($deliver_status == (-1)) { if($deliver_status == (-1)) {
update_queue_time($q_item['id']); update_queue_time($q_item['id']);

View file

@ -436,7 +436,7 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
if (($contact) && ($contact['network'] === NETWORK_DIASPORA)) { if (($contact) && ($contact['network'] === NETWORK_DIASPORA)) {
require_once('include/diaspora.php'); require_once('include/diaspora.php');
$ret = diaspora::send_share($user[0],$r[0]); $ret = Diaspora::send_share($user[0],$r[0]);
logger('share returns: ' . $ret); logger('share returns: ' . $ret);
} }

View file

@ -52,12 +52,12 @@ function fetch_init(App &$a){
} }
$user = $r[0]; $user = $r[0];
$status = diaspora::build_status($item[0], $user); $status = Diaspora::build_status($item[0], $user);
$xml = diaspora::build_post_xml($status["type"], $status["message"]); $xml = Diaspora::build_post_xml($status["type"], $status["message"]);
// Send the envelope // Send the envelope
header("Content-Type: application/magic-envelope+xml; charset=utf-8"); header("Content-Type: application/magic-envelope+xml; charset=utf-8");
echo diaspora::build_magic_envelope($xml, $user); echo Diaspora::build_magic_envelope($xml, $user);
killme(); killme();
} }

View file

@ -966,7 +966,7 @@ function item_post(App &$a) {
// Store the comment signature information in case we need to relay to Diaspora // Store the comment signature information in case we need to relay to Diaspora
diaspora::store_comment_signature($datarray, $author, ($self ? $user['prvkey'] : false), $post_id); Diaspora::store_comment_signature($datarray, $author, ($self ? $user['prvkey'] : false), $post_id);
} else { } else {
$parent = $post_id; $parent = $post_id;

View file

@ -54,8 +54,8 @@ function p_init($a){
} }
$user = $r[0]; $user = $r[0];
$status = diaspora::build_status($item[0], $user); $status = Diaspora::build_status($item[0], $user);
$xml = diaspora::build_post_xml($status["type"], $status["message"]); $xml = Diaspora::build_post_xml($status["type"], $status["message"]);
header("Content-Type: application/xml; charset=utf-8"); header("Content-Type: application/xml; charset=utf-8");
echo $xml; echo $xml;

View file

@ -54,7 +54,7 @@ function receive_post(App &$a) {
logger('mod-diaspora: message is okay', LOGGER_DEBUG); logger('mod-diaspora: message is okay', LOGGER_DEBUG);
$msg = diaspora::decode($importer,$xml); $msg = Diaspora::decode($importer,$xml);
logger('mod-diaspora: decoded', LOGGER_DEBUG); logger('mod-diaspora: decoded', LOGGER_DEBUG);
@ -67,9 +67,9 @@ function receive_post(App &$a) {
$ret = 0; $ret = 0;
if($public) { if($public) {
diaspora::dispatch_public($msg); Diaspora::dispatch_public($msg);
} else { } else {
$ret = diaspora::dispatch($importer,$msg); $ret = Diaspora::dispatch($importer,$msg);
} }
http_status_exit(($ret) ? $ret : 200); http_status_exit(($ret) ? $ret : 200);

View file

@ -38,9 +38,9 @@ class Item extends BaseObject {
$this->set_template('wall'); $this->set_template('wall');
$this->toplevel = ($this->get_id() == $this->get_data_value('parent')); $this->toplevel = ($this->get_id() == $this->get_data_value('parent'));
if(is_array($_SESSION['remote'])) { if (is_array($_SESSION['remote'])) {
foreach($_SESSION['remote'] as $visitor) { foreach ($_SESSION['remote'] as $visitor) {
if($visitor['cid'] == $this->get_data_value('contact-id')) { if ($visitor['cid'] == $this->get_data_value('contact-id')) {
$this->visiting = true; $this->visiting = true;
break; break;
} }
@ -349,7 +349,7 @@ class Item extends BaseObject {
// Diaspora isn't able to do likes on comments - but red does // Diaspora isn't able to do likes on comments - but red does
if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND
!diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) { !Diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) {
unset($buttons["like"]); unset($buttons["like"]);
} }