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

Signed-off-by: Roland Haeder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2016-12-31 17:59:14 +01:00
commit 9ca789b952
No known key found for this signature in database
GPG key ID: B72F8185C6C7BD78
8 changed files with 289 additions and 127 deletions

View file

@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_CODENAME', 'Asparagus');
define ( 'FRIENDICA_VERSION', '3.5.1-dev' ); define ( 'FRIENDICA_VERSION', '3.5.1-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1210 ); define ( 'DB_UPDATE_VERSION', 1211 );
/** /**
* @brief Constant with a HTML line break. * @brief Constant with a HTML line break.

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 3.5.1-dev (Asparagus) -- Friendica 3.5.1-dev (Asparagus)
-- DB_UPDATE_VERSION 1210 -- DB_UPDATE_VERSION 1211
-- ------------------------------------------ -- ------------------------------------------
@ -212,6 +212,7 @@ CREATE TABLE IF NOT EXISTS `deliverq` (
-- --
CREATE TABLE IF NOT EXISTS `event` ( CREATE TABLE IF NOT EXISTS `event` (
`id` int(11) NOT NULL auto_increment, `id` int(11) NOT NULL auto_increment,
`guid` varchar(255) NOT NULL DEFAULT '',
`uid` int(11) NOT NULL DEFAULT 0, `uid` int(11) NOT NULL DEFAULT 0,
`cid` int(11) NOT NULL DEFAULT 0, `cid` int(11) NOT NULL DEFAULT 0,
`uri` varchar(255) NOT NULL DEFAULT '', `uri` varchar(255) NOT NULL DEFAULT '',

View file

@ -622,6 +622,7 @@ function db_definition($charset) {
$database["event"] = array( $database["event"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),

View file

@ -518,15 +518,6 @@ function delivery_run(&$argv, &$argc){
if (!$contact['pubkey'] && !$public_message) if (!$contact['pubkey'] && !$public_message)
break; break;
$unsupported_activities = array(ACTIVITY_DISLIKE, ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE);
//don't transmit activities which are not supported by diaspora
foreach($unsupported_activities as $act) {
if (activity_match($target_item['verb'],$act)) {
break 2;
}
}
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);

View file

@ -18,6 +18,7 @@ require_once("include/group.php");
require_once("include/xml.php"); require_once("include/xml.php");
require_once("include/datetime.php"); require_once("include/datetime.php");
require_once("include/queue_fn.php"); require_once("include/queue_fn.php");
require_once("include/cache.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
@ -87,7 +88,7 @@ class Diaspora {
* *
* @return string the repaired signature * @return string the repaired signature
*/ */
private function repair_signature($signature, $handle = "", $level = 1) { private static function repair_signature($signature, $handle = "", $level = 1) {
if ($signature == "") if ($signature == "")
return ($signature); return ($signature);
@ -111,7 +112,7 @@ class Diaspora {
* *
* @return string verified data * @return string verified data
*/ */
private function verify_magic_envelope($envelope) { private static function verify_magic_envelope($envelope) {
$basedom = parse_xml_string($envelope, false); $basedom = parse_xml_string($envelope, false);
@ -412,7 +413,7 @@ class Diaspora {
* *
* @return bool Is the posting valid? * @return bool Is the posting valid?
*/ */
private function valid_posting($msg, &$fields) { private static function valid_posting($msg, &$fields) {
$data = parse_xml_string($msg["message"], false); $data = parse_xml_string($msg["message"], false);
@ -520,7 +521,7 @@ class Diaspora {
$key = self::key($msg["author"]); $key = self::key($msg["author"]);
if (!rsa_verify($signed_data, $parent_author_signature, $key, "sha256")) { if (!rsa_verify($signed_data, $parent_author_signature, $key, "sha256")) {
logger("No valid parent author signature for author ".$msg["author"]. " in type ".$type." - signed data: ".$signed_data." - Message: ".$msg["message"]." - Signature ".$parent_author_signature, LOGGER_DEBUG); logger("No valid parent author signature for parent author ".$msg["author"]. " in type ".$type." - signed data: ".$signed_data." - Message: ".$msg["message"]." - Signature ".$parent_author_signature, LOGGER_DEBUG);
return false; return false;
} }
} }
@ -528,7 +529,7 @@ class Diaspora {
$key = self::key($fields->author); $key = self::key($fields->author);
if (!rsa_verify($signed_data, $author_signature, $key, "sha256")) { if (!rsa_verify($signed_data, $author_signature, $key, "sha256")) {
logger("No valid author signature for author ".$msg["author"]. " in type ".$type." - signed data: ".$signed_data." - Message: ".$msg["message"]." - Signature ".$author_signature, LOGGER_DEBUG); logger("No valid author signature for author ".$fields->author. " in type ".$type." - signed data: ".$signed_data." - Message: ".$msg["message"]." - Signature ".$author_signature, LOGGER_DEBUG);
return false; return false;
} else } else
return true; return true;
@ -541,7 +542,7 @@ class Diaspora {
* *
* @return string The public key * @return string The public key
*/ */
private function key($handle) { private static function key($handle) {
$handle = strval($handle); $handle = strval($handle);
logger("Fetching diaspora key for: ".$handle); logger("Fetching diaspora key for: ".$handle);
@ -560,7 +561,7 @@ class Diaspora {
* *
* @return array the queried data * @return array the queried data
*/ */
private function person_by_handle($handle) { private static function person_by_handle($handle) {
$r = q("SELECT * FROM `fcontact` WHERE `network` = '%s' AND `addr` = '%s' LIMIT 1", $r = q("SELECT * FROM `fcontact` WHERE `network` = '%s' AND `addr` = '%s' LIMIT 1",
dbesc(NETWORK_DIASPORA), dbesc(NETWORK_DIASPORA),
@ -601,7 +602,7 @@ class Diaspora {
* *
* @return string The id of the fcontact entry * @return string The id of the fcontact entry
*/ */
private function add_fcontact($arr, $update = false) { private static function add_fcontact($arr, $update = false) {
if($update) { if($update) {
$r = q("UPDATE `fcontact` SET $r = q("UPDATE `fcontact` SET
@ -734,7 +735,7 @@ class Diaspora {
* *
* @return The contact id * @return The contact id
*/ */
private function contact_by_handle($uid, $handle) { private static function contact_by_handle($uid, $handle) {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `addr` = '%s' LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `addr` = '%s' LIMIT 1",
intval($uid), intval($uid),
dbesc($handle) dbesc($handle)
@ -765,7 +766,7 @@ class Diaspora {
* *
* @return bool is the contact allowed to post? * @return bool is the contact allowed to post?
*/ */
private function post_allow($importer, $contact, $is_comment = false) { private static function post_allow($importer, $contact, $is_comment = false) {
// perhaps we were already sharing with this person. Now they're sharing with us. // perhaps we were already sharing with this person. Now they're sharing with us.
// That makes us friends. // That makes us friends.
@ -804,7 +805,7 @@ class Diaspora {
* *
* @return array The contact data * @return array The contact data
*/ */
private function allowed_contact_by_handle($importer, $handle, $is_comment = false) { private static function allowed_contact_by_handle($importer, $handle, $is_comment = false) {
$contact = self::contact_by_handle($importer["uid"], $handle); $contact = self::contact_by_handle($importer["uid"], $handle);
if (!$contact) { if (!$contact) {
logger("A Contact for handle ".$handle." and user ".$importer["uid"]." was not found"); logger("A Contact for handle ".$handle." and user ".$importer["uid"]." was not found");
@ -826,7 +827,7 @@ class Diaspora {
* *
* @return int|bool message id if the message already was stored into the system - or false. * @return int|bool message id if the message already was stored into the system - or false.
*/ */
private function message_exists($uid, $guid) { private static function message_exists($uid, $guid) {
$r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1", $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
intval($uid), intval($uid),
dbesc($guid) dbesc($guid)
@ -845,7 +846,7 @@ class Diaspora {
* *
* @param array $item The item array * @param array $item The item array
*/ */
private function fetch_guid($item) { private static function fetch_guid($item) {
preg_replace_callback("&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi", preg_replace_callback("&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi",
function ($match) use ($item){ function ($match) use ($item){
return(self::fetch_guid_sub($match, $item)); return(self::fetch_guid_sub($match, $item));
@ -890,7 +891,7 @@ class Diaspora {
* @param array $match array containing a link that has to be checked for a message link * @param array $match array containing a link that has to be checked for a message link
* @param array $item The item array * @param array $item The item array
*/ */
private function fetch_guid_sub($match, $item) { private static function fetch_guid_sub($match, $item) {
if (!self::store_by_guid($match[1], $item["author-link"])) if (!self::store_by_guid($match[1], $item["author-link"]))
self::store_by_guid($match[1], $item["owner-link"]); self::store_by_guid($match[1], $item["owner-link"]);
} }
@ -904,7 +905,7 @@ class Diaspora {
* *
* @return int the message id of the stored message or false * @return int the message id of the stored message or false
*/ */
private function store_by_guid($guid, $server, $uid = 0) { private static function store_by_guid($guid, $server, $uid = 0) {
$serverparts = parse_url($server); $serverparts = parse_url($server);
$server = $serverparts["scheme"]."://".$serverparts["host"]; $server = $serverparts["scheme"]."://".$serverparts["host"];
@ -933,7 +934,7 @@ class Diaspora {
* 'author' => The author handle * 'author' => The author handle
* 'key' => The public key of the author * 'key' => The public key of the author
*/ */
private function message($guid, $server, $level = 0) { private static function message($guid, $server, $level = 0) {
if ($level > 5) if ($level > 5)
return false; return false;
@ -1009,7 +1010,7 @@ class Diaspora {
* *
* @return array the item record * @return array the item record
*/ */
private function parent_item($uid, $guid, $author, $contact) { private static function parent_item($uid, $guid, $author, $contact) {
$r = q("SELECT `id`, `body`, `wall`, `uri`, `private`, `origin`, $r = q("SELECT `id`, `body`, `wall`, `uri`, `private`, `origin`,
`author-name`, `author-link`, `author-avatar`, `author-name`, `author-link`, `author-avatar`,
`owner-name`, `owner-link`, `owner-avatar` `owner-name`, `owner-link`, `owner-avatar`
@ -1055,7 +1056,7 @@ class Diaspora {
* 'cid' => contact id * 'cid' => contact id
* 'network' => network type * 'network' => network type
*/ */
private function author_contact_by_url($contact, $person, $uid) { private static function author_contact_by_url($contact, $person, $uid) {
$r = q("SELECT `id`, `network`, `url` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT `id`, `network`, `url` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
dbesc(normalise_link($person["url"])), intval($uid)); dbesc(normalise_link($person["url"])), intval($uid));
@ -1093,7 +1094,7 @@ class Diaspora {
* *
* @return string the post link * @return string the post link
*/ */
private function plink($addr, $guid) { private static function plink($addr, $guid) {
$r = q("SELECT `url`, `nick`, `network` FROM `fcontact` WHERE `addr`='%s' LIMIT 1", dbesc($addr)); $r = q("SELECT `url`, `nick`, `network` FROM `fcontact` WHERE `addr`='%s' LIMIT 1", dbesc($addr));
// Fallback // Fallback
@ -1123,7 +1124,7 @@ class Diaspora {
* *
* @return bool Success * @return bool Success
*/ */
private function receive_account_deletion($importer, $data) { private static function receive_account_deletion($importer, $data) {
/// @todo Account deletion should remove the contact from the global contacts as well /// @todo Account deletion should remove the contact from the global contacts as well
@ -1145,16 +1146,38 @@ class Diaspora {
* *
* @param string $author Author handle * @param string $author Author handle
* @param string $guid Message guid * @param string $guid Message guid
* @param boolean $onlyfound Only return uri when found in the database
* *
* @return string The constructed uri or the one from our database * @return string The constructed uri or the one from our database
*/ */
private function get_uri_from_guid($author, $guid) { private static function get_uri_from_guid($author, $guid, $onlyfound = false) {
$r = q("SELECT `uri` FROM `item` WHERE `guid` = '%s' LIMIT 1", dbesc($guid)); $r = q("SELECT `uri` FROM `item` WHERE `guid` = '%s' LIMIT 1", dbesc($guid));
if ($r) if (dbm::is_result($r)) {
return $r[0]["uri"]; return $r[0]["uri"];
else } elseif (!$onlyfound) {
return $author.":".$guid; return $author.":".$guid;
}
return "";
}
/**
* @brief Fetch the guid from our database with a given uri
*
* @param string $author Author handle
* @param string $uri Message uri
*
* @return string The post guid
*/
private static function get_guid_from_uri($uri, $uid) {
$r = q("SELECT `guid` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($uri), intval($uid));
if (dbm::is_result($r)) {
return $r[0]["guid"];
} else {
return false;
}
} }
/** /**
@ -1167,7 +1190,7 @@ class Diaspora {
* *
* @return int The message id of the generated comment or "false" if there was an error * @return int The message id of the generated comment or "false" if there was an error
*/ */
private function receive_comment($importer, $sender, $data, $xml) { private static function receive_comment($importer, $sender, $data, $xml) {
$guid = notags(unxmlify($data->guid)); $guid = notags(unxmlify($data->guid));
$parent_guid = notags(unxmlify($data->parent_guid)); $parent_guid = notags(unxmlify($data->parent_guid));
$text = unxmlify($data->text); $text = unxmlify($data->text);
@ -1179,6 +1202,13 @@ class Diaspora {
$created_at = datetime_convert(); $created_at = datetime_convert();
} }
if (isset($data->thread_parent_guid)) {
$thread_parent_guid = notags(unxmlify($data->thread_parent_guid));
$thr_uri = self::get_uri_from_guid("", $thread_parent_guid, true);
} else {
$thr_uri = "";
}
$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;
@ -1223,7 +1253,12 @@ class Diaspora {
$datarray["type"] = "remote-comment"; $datarray["type"] = "remote-comment";
$datarray["verb"] = ACTIVITY_POST; $datarray["verb"] = ACTIVITY_POST;
$datarray["gravity"] = GRAVITY_COMMENT; $datarray["gravity"] = GRAVITY_COMMENT;
$datarray["parent-uri"] = $parent_item["uri"];
if ($thr_uri != "") {
$datarray["parent-uri"] = $thr_uri;
} else {
$datarray["parent-uri"] = $parent_item["uri"];
}
$datarray["object-type"] = ACTIVITY_OBJ_COMMENT; $datarray["object-type"] = ACTIVITY_OBJ_COMMENT;
$datarray["object"] = $xml; $datarray["object"] = $xml;
@ -1271,7 +1306,7 @@ class Diaspora {
* *
* @return bool "true" if it was successful * @return bool "true" if it was successful
*/ */
private function receive_conversation_message($importer, $contact, $data, $msg, $mesg, $conversation) { private static function receive_conversation_message($importer, $contact, $data, $msg, $mesg, $conversation) {
$guid = notags(unxmlify($data->guid)); $guid = notags(unxmlify($data->guid));
$subject = notags(unxmlify($data->subject)); $subject = notags(unxmlify($data->subject));
$author = notags(unxmlify($data->author)); $author = notags(unxmlify($data->author));
@ -1396,7 +1431,7 @@ class Diaspora {
* *
* @return bool Success * @return bool Success
*/ */
private function receive_conversation($importer, $msg, $data) { private static function receive_conversation($importer, $msg, $data) {
$guid = notags(unxmlify($data->guid)); $guid = notags(unxmlify($data->guid));
$subject = notags(unxmlify($data->subject)); $subject = notags(unxmlify($data->subject));
$created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at))); $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
@ -1462,7 +1497,7 @@ class Diaspora {
* *
* @return string the body * @return string the body
*/ */
private function construct_like_body($contact, $parent_item, $guid) { private static function construct_like_body($contact, $parent_item, $guid) {
$bodyverb = t('%1$s likes %2$s\'s %3$s'); $bodyverb = t('%1$s likes %2$s\'s %3$s');
$ulink = "[url=".$contact["url"]."]".$contact["name"]."[/url]"; $ulink = "[url=".$contact["url"]."]".$contact["name"]."[/url]";
@ -1480,7 +1515,7 @@ class Diaspora {
* *
* @return string The XML * @return string The XML
*/ */
private function construct_like_object($importer, $parent_item) { private static function construct_like_object($importer, $parent_item) {
$objtype = ACTIVITY_OBJ_NOTE; $objtype = ACTIVITY_OBJ_NOTE;
$link = '<link rel="alternate" type="text/html" href="'.App::get_baseurl()."/display/".$importer["nickname"]."/".$parent_item["id"].'" />'; $link = '<link rel="alternate" type="text/html" href="'.App::get_baseurl()."/display/".$importer["nickname"]."/".$parent_item["id"].'" />';
$parent_body = $parent_item["body"]; $parent_body = $parent_item["body"];
@ -1504,7 +1539,7 @@ class Diaspora {
* *
* @return int The message id of the generated like or "false" if there was an error * @return int The message id of the generated like or "false" if there was an error
*/ */
private function receive_like($importer, $sender, $data) { private static function receive_like($importer, $sender, $data) {
$positive = notags(unxmlify($data->positive)); $positive = notags(unxmlify($data->positive));
$guid = notags(unxmlify($data->guid)); $guid = notags(unxmlify($data->guid));
$parent_type = notags(unxmlify($data->parent_type)); $parent_type = notags(unxmlify($data->parent_type));
@ -1601,7 +1636,7 @@ class Diaspora {
* *
* @return bool Success? * @return bool Success?
*/ */
private function receive_message($importer, $data) { private static function receive_message($importer, $data) {
$guid = notags(unxmlify($data->guid)); $guid = notags(unxmlify($data->guid));
$parent_guid = notags(unxmlify($data->parent_guid)); $parent_guid = notags(unxmlify($data->parent_guid));
$text = unxmlify($data->text); $text = unxmlify($data->text);
@ -1682,7 +1717,7 @@ class Diaspora {
* *
* @return bool always true * @return bool always true
*/ */
private function receive_participation($importer, $data) { private static function receive_participation($importer, $data) {
// I'm not sure if we can fully support this message type // I'm not sure if we can fully support this message type
return true; return true;
} }
@ -1695,7 +1730,7 @@ class Diaspora {
* *
* @return bool always true * @return bool always true
*/ */
private function receive_photo($importer, $data) { private static function receive_photo($importer, $data) {
// There doesn't seem to be a reason for this function, since the photo data is transmitted in the status message as well // There doesn't seem to be a reason for this function, since the photo data is transmitted in the status message as well
return true; return true;
} }
@ -1708,7 +1743,7 @@ class Diaspora {
* *
* @return bool always true * @return bool always true
*/ */
private function receive_poll_participation($importer, $data) { private static function receive_poll_participation($importer, $data) {
// We don't support polls by now // We don't support polls by now
return true; return true;
} }
@ -1721,7 +1756,7 @@ class Diaspora {
* *
* @return bool Success * @return bool Success
*/ */
private function receive_profile($importer, $data) { private static function receive_profile($importer, $data) {
$author = strtolower(notags(unxmlify($data->author))); $author = strtolower(notags(unxmlify($data->author)));
$contact = self::contact_by_handle($importer["uid"], $author); $contact = self::contact_by_handle($importer["uid"], $author);
@ -1812,7 +1847,7 @@ class Diaspora {
* @param array $importer Array of the importer user * @param array $importer Array of the importer user
* @param array $contact The contact that send the request * @param array $contact The contact that send the request
*/ */
private function receive_request_make_friend($importer, $contact) { private static function receive_request_make_friend($importer, $contact) {
$a = get_app(); $a = get_app();
@ -1881,18 +1916,18 @@ class Diaspora {
* *
* @return string The XML * @return string The XML
*/ */
private function construct_new_friend_object($contact) { private static function construct_new_friend_object($contact) {
$objtype = ACTIVITY_OBJ_PERSON; $objtype = ACTIVITY_OBJ_PERSON;
$link = '<link rel="alternate" type="text/html" href="'.$contact["url"].'" />'."\n". $link = '<link rel="alternate" type="text/html" href="'.$contact["url"].'" />'."\n".
'<link rel="photo" type="image/jpeg" href="'.$contact["thumb"].'" />'."\n"; '<link rel="photo" type="image/jpeg" href="'.$contact["thumb"].'" />'."\n";
$xmldata = array("object" => array("type" => $objtype, $xmldata = array("object" => array("type" => $objtype,
"title" => $contact["name"], "title" => $contact["name"],
"id" => $contact["url"]."/".$contact["name"], "id" => $contact["url"]."/".$contact["name"],
"link" => $link)); "link" => $link));
return xml::from_array($xmldata, $xml, true); return xml::from_array($xmldata, $xml, true);
} }
/** /**
* @brief Processes incoming sharing notification * @brief Processes incoming sharing notification
@ -1902,7 +1937,7 @@ class Diaspora {
* *
* @return bool Success * @return bool Success
*/ */
private function receive_contact_request($importer, $data) { private static function receive_contact_request($importer, $data) {
$author = unxmlify($data->author); $author = unxmlify($data->author);
$recipient = unxmlify($data->recipient); $recipient = unxmlify($data->recipient);
@ -2083,7 +2118,7 @@ class Diaspora {
* *
* @return array The fetched item * @return array The fetched item
*/ */
private function original_item($guid, $orig_author, $author) { private static function original_item($guid, $orig_author, $author) {
// Do we already have this item? // Do we already have this item?
$r = q("SELECT `body`, `tag`, `app`, `created`, `object-type`, `uri`, `guid`, $r = q("SELECT `body`, `tag`, `app`, `created`, `object-type`, `uri`, `guid`,
@ -2154,7 +2189,7 @@ class Diaspora {
* *
* @return int the message id * @return int the message id
*/ */
private function receive_reshare($importer, $data, $xml) { private static function receive_reshare($importer, $data, $xml) {
$root_author = notags(unxmlify($data->root_author)); $root_author = notags(unxmlify($data->root_author));
$root_guid = notags(unxmlify($data->root_guid)); $root_guid = notags(unxmlify($data->root_guid));
$guid = notags(unxmlify($data->guid)); $guid = notags(unxmlify($data->guid));
@ -2233,7 +2268,7 @@ class Diaspora {
* *
* @return bool success * @return bool success
*/ */
private function item_retraction($importer, $contact, $data) { private static function item_retraction($importer, $contact, $data) {
$target_type = notags(unxmlify($data->target_type)); $target_type = notags(unxmlify($data->target_type));
$target_guid = notags(unxmlify($data->target_guid)); $target_guid = notags(unxmlify($data->target_guid));
$author = notags(unxmlify($data->author)); $author = notags(unxmlify($data->author));
@ -2290,7 +2325,7 @@ class Diaspora {
* *
* @return bool Success * @return bool Success
*/ */
private function receive_retraction($importer, $sender, $data) { private static function receive_retraction($importer, $sender, $data) {
$target_type = notags(unxmlify($data->target_type)); $target_type = notags(unxmlify($data->target_type));
$contact = self::contact_by_handle($importer["uid"], $sender); $contact = self::contact_by_handle($importer["uid"], $sender);
@ -2332,7 +2367,7 @@ class Diaspora {
* *
* @return int The message id of the newly created item * @return int The message id of the newly created item
*/ */
private function receive_status_message($importer, $data, $xml) { private static function receive_status_message($importer, $data, $xml) {
$raw_message = unxmlify($data->raw_message); $raw_message = unxmlify($data->raw_message);
$guid = notags(unxmlify($data->guid)); $guid = notags(unxmlify($data->guid));
$author = notags(unxmlify($data->author)); $author = notags(unxmlify($data->author));
@ -2443,7 +2478,7 @@ 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 static function my_handle($contact) {
if ($contact["addr"] != "") { if ($contact["addr"] != "") {
return $contact["addr"]; return $contact["addr"];
} }
@ -2504,7 +2539,7 @@ class Diaspora {
* *
* @return string The envelope * @return string The envelope
*/ */
private function build_public_message($msg, $user, $contact, $prvkey, $pubkey) { private static function build_public_message($msg, $user, $contact, $prvkey, $pubkey) {
logger("Message: ".$msg, LOGGER_DATA); logger("Message: ".$msg, LOGGER_DATA);
@ -2550,7 +2585,7 @@ class Diaspora {
* *
* @return string The envelope * @return string The envelope
*/ */
private function build_private_message($msg, $user, $contact, $prvkey, $pubkey) { private static function build_private_message($msg, $user, $contact, $prvkey, $pubkey) {
logger("Message: ".$msg, LOGGER_DATA); logger("Message: ".$msg, LOGGER_DATA);
@ -2641,7 +2676,7 @@ class Diaspora {
* *
* @return string The message that will be transmitted to other servers * @return string The message that will be transmitted to other servers
*/ */
private function build_message($msg, $user, $contact, $prvkey, $pubkey, $public = false) { private static function build_message($msg, $user, $contact, $prvkey, $pubkey, $public = false) {
if ($public) if ($public)
$magic_env = self::build_public_message($msg,$user,$contact,$prvkey,$pubkey); $magic_env = self::build_public_message($msg,$user,$contact,$prvkey,$pubkey);
@ -2661,7 +2696,7 @@ class Diaspora {
* *
* @return string The signature * @return string The signature
*/ */
private function signature($owner, $message) { private static function signature($owner, $message) {
$sigmsg = $message; $sigmsg = $message;
unset($sigmsg["author_signature"]); unset($sigmsg["author_signature"]);
unset($sigmsg["parent_author_signature"]); unset($sigmsg["parent_author_signature"]);
@ -2768,7 +2803,7 @@ class Diaspora {
* *
* @return int Result of the transmission * @return int Result of the transmission
*/ */
private function build_and_transmit($owner, $contact, $type, $message, $public_batch = false, $guid = "", $spool = false) { private static function build_and_transmit($owner, $contact, $type, $message, $public_batch = false, $guid = "", $spool = false) {
$msg = self::build_post_xml($type, $message); $msg = self::build_post_xml($type, $message);
@ -2909,6 +2944,80 @@ class Diaspora {
return($ret); return($ret);
} }
/**
* @brief Create an event array
*
* @param integer $event_id The id of the event
*
* @return array with event data
*/
private static function build_event($event_id) {
$r = q("SELECT `guid`, `uid`, `start`, `finish`, `nofinish`, `summary`, `desc`, `location`, `adjust` FROM `event` WHERE `id` = %d", intval($event_id));
if (!dbm::is_result($r)) {
return array();
}
$event = $r[0];
$eventdata = array();
$r = q("SELECT `timezone` FROM `user` WHERE `uid` = %d", intval($event['uid']));
if (!dbm::is_result($r)) {
return array();
}
$user = $r[0];
$r = q("SELECT `addr`, `nick` FROM `contact` WHERE `uid` = %d AND `self`", intval($event['uid']));
if (!dbm::is_result($r)) {
return array();
}
$owner = $r[0];
$eventdata['author'] = self::my_handle($owner);
if ($event['guid']) {
$eventdata['guid'] = $event['guid'];
}
$mask = 'Y-m-d\TH:i:s\Z';
/// @todo - establish "all day" events in Friendica
$eventdata["all_day"] = "false";
if (!$event['adjust']) {
$eventdata['timezone'] = $user['timezone'];
if ($eventdata['timezone'] == "") {
$eventdata['timezone'] = 'UTC';
}
}
if ($event['start']) {
$eventdata['start'] = datetime_convert($eventdata['timezone'], "UTC", $event['start'], $mask);
}
if ($event['finish'] AND !$event['nofinish']) {
$eventdata['end'] = datetime_convert($eventdata['timezone'], "UTC", $event['finish'], $mask);
}
if ($event['summary']) {
$eventdata['summary'] = html_entity_decode(bb2diaspora($event['summary']));
}
if ($event['desc']) {
$eventdata['description'] = html_entity_decode(bb2diaspora($event['desc']));
}
if ($event['location']) {
$location = array();
$location["address"] = html_entity_decode(bb2diaspora($event['location']));
$location["lat"] = 0;
$location["lng"] = 0;
$eventdata['location'] = $location;
}
return $eventdata;
}
/** /**
* @brief Create a post (status message or reshare) * @brief Create a post (status message or reshare)
* *
@ -2921,11 +3030,18 @@ class Diaspora {
*/ */
public static function build_status($item, $owner) { public static function build_status($item, $owner) {
$cachekey = "diaspora:build_status:".$item['guid'];
$result = Cache::get($cachekey);
if (!is_null($result)) {
return $result;
}
$myaddr = self::my_handle($owner); $myaddr = self::my_handle($owner);
$public = (($item["private"]) ? "false" : "true"); $public = (($item["private"]) ? "false" : "true");
$created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d H:i:s \U\T\C'); $created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
// Detect a share element and do a reshare // Detect a share element and do a reshare
if (!$item['private'] AND ($ret = self::is_reshare($item["body"]))) { if (!$item['private'] AND ($ret = self::is_reshare($item["body"]))) {
@ -2982,9 +3098,24 @@ class Diaspora {
unset($message["location"]); unset($message["location"]);
} }
if ($item['event-id'] > 0) {
$event = self::build_event($item['event-id']);
if (count($event)) {
$message['event'] = $event;
/// @todo Once Diaspora supports it, we will remove the body
// $message['raw_message'] = '';
}
}
$type = "status_message"; $type = "status_message";
} }
return array("type" => $type, "message" => $message);
$msg = array("type" => $type, "message" => $message);
Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR);
return $msg;
} }
/** /**
@ -3012,7 +3143,7 @@ class Diaspora {
* *
* @return array The data for a "like" * @return array The data for a "like"
*/ */
private function construct_like($item, $owner) { private static function construct_like($item, $owner) {
$p = q("SELECT `guid`, `uri`, `parent-uri` FROM `item` WHERE `uri` = '%s' LIMIT 1", $p = q("SELECT `guid`, `uri`, `parent-uri` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($item["thr-parent"])); dbesc($item["thr-parent"]));
@ -3022,7 +3153,11 @@ class Diaspora {
$parent = $p[0]; $parent = $p[0];
$target_type = ($parent["uri"] === $parent["parent-uri"] ? "Post" : "Comment"); $target_type = ($parent["uri"] === $parent["parent-uri"] ? "Post" : "Comment");
$positive = "true"; if ($item['verb'] === ACTIVITY_LIKE) {
$positive = "true";
} elseif ($item['verb'] === ACTIVITY_DISLIKE) {
$positive = "false";
}
return(array("positive" => $positive, return(array("positive" => $positive,
"guid" => $item["guid"], "guid" => $item["guid"],
@ -3032,6 +3167,45 @@ class Diaspora {
"diaspora_handle" => self::my_handle($owner))); "diaspora_handle" => self::my_handle($owner)));
} }
/**
* @brief Creates an "EventParticipation" object
*
* @param array $item The item that will be exported
* @param array $owner the array of the item owner
*
* @return array The data for an "EventParticipation"
*/
private static function construct_attend($item, $owner) {
$p = q("SELECT `guid`, `uri`, `parent-uri` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($item["thr-parent"]));
if (!dbm::is_result($p))
return false;
$parent = $p[0];
switch ($item['verb']) {
case ACTIVITY_ATTEND:
$attend_answer = 'accepted';
break;
case ACTIVITY_ATTENDNO:
$attend_answer = 'declined';
break;
case ACTIVITY_ATTENDMAYBE:
$attend_answer = 'tentative';
break;
default:
logger('Unknown verb '.$item['verb'].' in item '.$item['guid']);
return false;
}
return(array("author" => self::my_handle($owner),
"guid" => $item["guid"],
"parent_guid" => $parent["guid"],
"status" => $attend_answer,
"author_signature" => ""));
}
/** /**
* @brief Creates the object for a comment * @brief Creates the object for a comment
* *
@ -3040,7 +3214,14 @@ class Diaspora {
* *
* @return array The data for a comment * @return array The data for a comment
*/ */
private function construct_comment($item, $owner) { private static function construct_comment($item, $owner) {
$cachekey = "diaspora:construct_comment:".$item['guid'];
$result = Cache::get($cachekey);
if (!is_null($result)) {
return $result;
}
$p = q("SELECT `guid` FROM `item` WHERE `parent` = %d AND `id` = %d LIMIT 1", $p = q("SELECT `guid` FROM `item` WHERE `parent` = %d AND `id` = %d LIMIT 1",
intval($item["parent"]), intval($item["parent"]),
@ -3053,12 +3234,23 @@ class Diaspora {
$parent = $p[0]; $parent = $p[0];
$text = html_entity_decode(bb2diaspora($item["body"])); $text = html_entity_decode(bb2diaspora($item["body"]));
$created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
return(array("guid" => $item["guid"], $comment = array("guid" => $item["guid"],
"parent_guid" => $parent["guid"], "parent_guid" => $parent["guid"],
"author_signature" => "", "author_signature" => "",
"text" => $text, "text" => $text,
"diaspora_handle" => self::my_handle($owner))); /// @todo Currently disabled until Diaspora supports it: "created_at" => $created,
"diaspora_handle" => self::my_handle($owner));
// Send the thread parent guid only if it is a threaded comment
if ($item['thr-parent'] != $item['parent-uri']) {
$comment['thread_parent_guid'] = self::get_guid_from_uri($item['thr-parent'], $item['uid']);
}
Cache::set($cachekey, $comment, CACHE_QUARTER_HOUR);
return($comment);
} }
/** /**
@ -3073,7 +3265,10 @@ class Diaspora {
*/ */
public static function send_followup($item,$owner,$contact,$public_batch = false) { public static function send_followup($item,$owner,$contact,$public_batch = false) {
if($item['verb'] === ACTIVITY_LIKE) { if (in_array($item['verb'], array(ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE))) {
$message = self::construct_attend($item, $owner);
$type = "event_participation";
} elseif (in_array($item["verb"], array(ACTIVITY_LIKE, ACTIVITY_DISLIKE))) {
$message = self::construct_like($item, $owner); $message = self::construct_like($item, $owner);
$type = "like"; $type = "like";
} else { } else {
@ -3097,7 +3292,7 @@ class Diaspora {
* *
* @return string The message * @return string The message
*/ */
private function message_from_signature($item, $signature) { private static function message_from_signature($item, $signature) {
// Split the signed text // Split the signed text
$signed_parts = explode(";", $signature['signed_text']); $signed_parts = explode(";", $signature['signed_text']);
@ -3270,13 +3465,13 @@ class Diaspora {
$conv = array( $conv = array(
"guid" => $cnv["guid"], "guid" => $cnv["guid"],
"subject" => $cnv["subject"], "subject" => $cnv["subject"],
"created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d H:i:s \U\T\C'), "created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d\TH:i:s\Z'),
"diaspora_handle" => $cnv["creator"], "diaspora_handle" => $cnv["creator"],
"participant_handles" => $cnv["recips"] "participant_handles" => $cnv["recips"]
); );
$body = bb2diaspora($item["body"]); $body = bb2diaspora($item["body"]);
$created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d H:i:s \U\T\C'); $created = datetime_convert("UTC", "UTC", $item["created"], 'Y-m-d\TH:i:s\Z');
$signed_text = $item["guid"].";".$cnv["guid"].";".$body.";".$created.";".$myaddr.";".$cnv['guid']; $signed_text = $item["guid"].";".$cnv["guid"].";".$body.";".$created.";".$myaddr.";".$cnv['guid'];
$sig = base64_encode(rsa_sign($signed_text, $owner["uprvkey"], "sha256")); $sig = base64_encode(rsa_sign($signed_text, $owner["uprvkey"], "sha256"));
@ -3298,7 +3493,7 @@ class Diaspora {
} else { } else {
$message = array("guid" => $cnv["guid"], $message = array("guid" => $cnv["guid"],
"subject" => $cnv["subject"], "subject" => $cnv["subject"],
"created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d H:i:s \U\T\C'), "created_at" => datetime_convert("UTC", "UTC", $cnv['created'], 'Y-m-d\TH:i:s\Z'),
"message" => $msg, "message" => $msg,
"diaspora_handle" => $cnv["creator"], "diaspora_handle" => $cnv["creator"],
"participant_handles" => $cnv["recips"]); "participant_handles" => $cnv["recips"]);
@ -3427,26 +3622,13 @@ class Diaspora {
$message = self::construct_like($r[0], $contact); $message = self::construct_like($r[0], $contact);
$message["author_signature"] = self::signature($contact, $message); $message["author_signature"] = self::signature($contact, $message);
// In the future we will store the signature more flexible to support new fields. // We now store the signature more flexible to dynamically support new fields.
// Right now we cannot change this since old Friendica versions (prior to 3.5) can only handle this format. // This will break Diaspora compatibility with Friendica versions prior to 3.5.
// (We are transmitting this data here via DFRN) q("INSERT INTO `sign` (`iid`,`signed_text`) VALUES (%d,'%s')",
intval($message_id),
$signed_text = $message["positive"].";".$message["guid"].";".$message["target_type"].";". dbesc(json_encode($message))
$message["parent_guid"].";".$message["diaspora_handle"];
q("INSERT INTO `sign` (`iid`,`signed_text`,`signature`,`signer`) VALUES (%d,'%s','%s','%s')",
intval($post_id),
dbesc($signed_text),
dbesc($message["author_signature"]),
dbesc($message["diaspora_handle"])
); );
// This here will replace the lines above, once Diaspora changed its protocol
//q("INSERT INTO `sign` (`iid`,`signed_text`) VALUES (%d,'%s')",
// intval($message_id),
// dbesc(json_encode($message))
//);
logger('Stored diaspora like signature'); logger('Stored diaspora like signature');
return true; return true;
} }
@ -3473,25 +3655,13 @@ class Diaspora {
$message = self::construct_comment($item, $contact); $message = self::construct_comment($item, $contact);
$message["author_signature"] = self::signature($contact, $message); $message["author_signature"] = self::signature($contact, $message);
// In the future we will store the signature more flexible to support new fields. // We now store the signature more flexible to dynamically support new fields.
// Right now we cannot change this since old Friendica versions (prior to 3.5) can only handle this format. // This will break Diaspora compatibility with Friendica versions prior to 3.5.
// (We are transmitting this data here via DFRN) q("INSERT INTO `sign` (`iid`,`signed_text`) VALUES (%d,'%s')",
$signed_text = $message["guid"].";".$message["parent_guid"].";".
$message["text"].";".$message["diaspora_handle"];
q("INSERT INTO `sign` (`iid`,`signed_text`,`signature`,`signer`) VALUES (%d,'%s','%s','%s')",
intval($message_id), intval($message_id),
dbesc($signed_text), dbesc(json_encode($message))
dbesc($message["author_signature"]),
dbesc($message["diaspora_handle"])
); );
// This here will replace the lines above, once Diaspora changed its protocol
//q("INSERT INTO `sign` (`iid`,`signed_text`) VALUES (%d,'%s')",
// intval($message_id),
// dbesc(json_encode($message))
//);
logger('Stored diaspora comment signature'); logger('Stored diaspora comment signature');
return true; return true;
} }

View file

@ -246,6 +246,7 @@ function event_store($arr) {
$arr['cid'] = ((intval($arr['cid'])) ? intval($arr['cid']) : 0); $arr['cid'] = ((intval($arr['cid'])) ? intval($arr['cid']) : 0);
$arr['uri'] = (x($arr,'uri') ? $arr['uri'] : item_new_uri($a->get_hostname(),$arr['uid'])); $arr['uri'] = (x($arr,'uri') ? $arr['uri'] : item_new_uri($a->get_hostname(),$arr['uid']));
$arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0); $arr['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0);
$arr['guid'] = get_guid(32);
if($arr['cid']) if($arr['cid'])
$c = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", $c = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@ -333,16 +334,16 @@ function event_store($arr) {
call_hooks("event_updated", $arr['id']); call_hooks("event_updated", $arr['id']);
return $item_id; return $item_id;
} } else {
else {
// New event. Store it. // New event. Store it.
$r = q("INSERT INTO `event` ( `uid`,`cid`,`uri`,`created`,`edited`,`start`,`finish`,`summary`, `desc`,`location`,`type`, $r = q("INSERT INTO `event` (`uid`,`cid`,`guid`,`uri`,`created`,`edited`,`start`,`finish`,`summary`, `desc`,`location`,`type`,
`adjust`,`nofinish`,`allow_cid`,`allow_gid`,`deny_cid`,`deny_gid`) `adjust`,`nofinish`,`allow_cid`,`allow_gid`,`deny_cid`,`deny_gid`)
VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s' ) ", VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s' ) ",
intval($arr['uid']), intval($arr['uid']),
intval($arr['cid']), intval($arr['cid']),
dbesc($arr['guid']),
dbesc($arr['uri']), dbesc($arr['uri']),
dbesc($arr['created']), dbesc($arr['created']),
dbesc($arr['edited']), dbesc($arr['edited']),

View file

@ -334,7 +334,9 @@ class Item extends BaseObject {
} }
// Disable features that aren't available in several networks // Disable features that aren't available in several networks
if (($item["item_network"] != NETWORK_DFRN) AND isset($buttons["dislike"])) {
/// @todo Add NETWORK_DIASPORA when it will pass this information
if (!in_array($item["item_network"], array(NETWORK_DFRN)) AND isset($buttons["dislike"])) {
unset($buttons["dislike"],$isevent); unset($buttons["dislike"],$isevent);
$tagger = ''; $tagger = '';
} }
@ -347,17 +349,13 @@ class Item extends BaseObject {
unset($buttons["like"]); unset($buttons["like"]);
} }
// Diaspora isn't able to do likes on comments - but red does // Diaspora isn't able to do likes on comments - but Hubzilla does
/// @todo When Diaspora will pass this information we will remove these lines
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"]);
} }
// Diaspora doesn't has multithreaded comments
if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment')) {
unset($comment);
}
// Facebook can like comments - but it isn't programmed in the connector yet. // Facebook can like comments - but it isn't programmed in the connector yet.
if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"])) { if (($item["item_network"] == NETWORK_FACEBOOK) AND ($indent == 'comment') AND isset($buttons["like"])) {
unset($buttons["like"]); unset($buttons["like"]);

View file

@ -1,6 +1,6 @@
<?php <?php
define('UPDATE_VERSION' , 1210); define('UPDATE_VERSION' , 1211);
/** /**
* *