*
* @return string the repaired signature
*/
- function repair_signature($signature, $handle = "", $level = 1) {
+ private function repair_signature($signature, $handle = "", $level = 1) {
if ($signature == "")
return ($signature);
* 'author' -> author diaspora handle
* 'key' -> author public key (converted to pkcs#8)
*/
- function decode($importer, $xml) {
+ public static function decode($importer, $xml) {
$public = false;
$basedom = parse_xml_string($xml);
*
* @param array $msg The post that will be dispatched
*
- * @return bool Was the message accepted?
+ * @return int The message id of the generated message, "true" or "false" if there was an error
*/
public static function dispatch_public($msg) {
// Use a dummy importer to import the data for the public copy
$importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
- $item_id = self::dispatch($importer,$msg);
+ $message_id = self::dispatch($importer,$msg);
// Now distribute it to the followers
$r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN
} else
logger("No subscribers for ".$msg["author"]." ".print_r($msg, true));
- return $item_id;
+ return $message_id;
}
/**
* @param array $importer Array of the importer user
* @param array $msg The post that will be dispatched
*
- * @return bool Was the message accepted?
+ * @return int The message id of the generated message, "true" or "false" if there was an error
*/
public static function dispatch($importer, $msg) {
case "comment":
return self::receive_comment($importer, $sender, $fields, $msg["message"]);
+ case "contact":
+ return self::receive_contact_request($importer, $fields);
+
case "conversation":
return self::receive_conversation($importer, $msg, $fields);
case "profile":
return self::receive_profile($importer, $fields);
- case "request":
- return self::receive_request($importer, $fields);
-
case "reshare":
return self::receive_reshare($importer, $fields, $msg["message"]);
if (in_array($type, array("signed_retraction", "relayable_retraction")))
$type = "retraction";
+ if ($type == "request")
+ $type = "contact";
+
$fields = new SimpleXMLElement("<".$type."/>");
$signed_data = "";
* @param string $handle The checked handle in the format user@domain.tld
* @param bool $is_comment Is the check for a comment?
*
- * @return bool is posting allowed?
+ * @return array The contact data
*/
private function allowed_contact_by_handle($importer, $handle, $is_comment = false) {
$contact = self::contact_by_handle($importer["uid"], $handle);
* @param array $person The record of the person
* @param int $uid The user id
*
- * @return array of contact id and network type
+ * @return array
+ * 'cid' => contact id
+ * 'network' => network type
*/
private function author_contact_by_url($contact, $person, $uid) {
// "positive" = "false" would be a Dislike - wich isn't currently supported by Diaspora
// We would accept this anyhow.
- if ($positive === "true")
+ if ($positive == "true")
$verb = ACTIVITY_LIKE;
else
$verb = ACTIVITY_DISLIKE;
*
* @return bool Success
*/
- private function receive_request($importer, $data) {
+ private function receive_contact_request($importer, $data) {
$author = unxmlify($data->author);
$recipient = unxmlify($data->recipient);
if (!$author || !$recipient)
return false;
- $contact = self::contact_by_handle($importer["uid"],$author);
+ // the current protocol version doesn't know these fields
+ // That means that we will assume their existance
+ if (isset($data->following))
+ $following = (unxmlify($data->following) == "true");
+ else
+ $following = true;
- if($contact) {
+ if (isset($data->sharing))
+ $sharing = (unxmlify($data->sharing) == "true");
+ else
+ $sharing = true;
- // perhaps we were already sharing with this person. Now they're sharing with us.
- // That makes us friends.
+ $contact = self::contact_by_handle($importer["uid"],$author);
- self::receive_request_make_friend($importer, $contact);
- return true;
+ // perhaps we were already sharing with this person. Now they're sharing with us.
+ // That makes us friends.
+ if ($contact) {
+ if ($following AND $sharing) {
+ self::receive_request_make_friend($importer, $contact);
+ return true;
+ } else /// @todo Handle all possible variations of adding and retracting of permissions
+ return false;
+ }
+
+ if (!$following AND $sharing AND in_array($importer["page-flags"], array(PAGE_SOAPBOX, PAGE_NORMAL))) {
+ logger("Author ".$author." wants to share with us - but doesn't want to listen. Request is ignored.", LOGGER_DEBUG);
+ return false;
+ } elseif (!$following AND !$sharing) {
+ logger("Author ".$author." doesn't want anything - and we don't know the author. Request is ignored.", LOGGER_DEBUG);
+ return false;
}
$ret = self::person_by_handle($author);
// but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX
// we are going to change the relationship and make them a follower.
- if($importer["page-flags"] == PAGE_FREELOVE)
+ if (($importer["page-flags"] == PAGE_FREELOVE) AND $sharing AND $following)
$new_relation = CONTACT_IS_FRIEND;
+ elseif (($importer["page-flags"] == PAGE_FREELOVE) AND $sharing)
+ $new_relation = CONTACT_IS_SHARING;
else
$new_relation = CONTACT_IS_FOLLOWER;
$link = $matches[1];
$ret["root_guid"] = preg_replace("=https?://(.*)/posts/(.*)=ism", "$2", $link);
- if (($ret["root_guid"] == $link) OR ($ret["root_guid"] == ""))
+ if (($ret["root_guid"] == $link) OR (trim($ret["root_guid"]) == ""))
return(false);
+
return($ret);
}