From ce4c542e3766ee33392dfe20bb50f762085868c9 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 27 Dec 2016 12:59:15 +0000 Subject: [PATCH 01/13] Support for threaded comments --- include/diaspora.php | 37 +++++++++++++++++++++++++++++++------ object/Item.php | 16 +++++++++------- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index e4c81dca49..77ca376b7d 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1157,6 +1157,23 @@ class Diaspora { return $author.":".$guid; } + /** + * @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; + } + /** * @brief Processes an incoming comment * @@ -2922,7 +2939,7 @@ class Diaspora { $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 if (!$item['private'] AND ($ret = self::is_reshare($item["body"]))) { @@ -3050,12 +3067,20 @@ class Diaspora { $parent = $p[0]; $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"], "author_signature" => "", "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']); + } + return($comment); } /** @@ -3267,13 +3292,13 @@ class Diaspora { $conv = array( "guid" => $cnv["guid"], "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"], "participant_handles" => $cnv["recips"] ); $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']; $sig = base64_encode(rsa_sign($signed_text, $owner["uprvkey"], "sha256")); @@ -3295,7 +3320,7 @@ class Diaspora { } else { $message = array("guid" => $cnv["guid"], "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, "diaspora_handle" => $cnv["creator"], "participant_handles" => $cnv["recips"]); diff --git a/object/Item.php b/object/Item.php index 1c6eaf5f94..4b3dfd5642 100644 --- a/object/Item.php +++ b/object/Item.php @@ -347,16 +347,18 @@ class Item extends BaseObject { unset($buttons["like"]); } + // Disabled for testing purposes + // Diaspora isn't able to do likes on comments - but red does - if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND - !Diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) { - unset($buttons["like"]); - } + //if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND + // !Diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) { + // unset($buttons["like"]); + //} // Diaspora doesn't has multithreaded comments - if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment')) { - unset($comment); - } + //if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment')) { + // unset($comment); + //} // 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"])) { From 6a511066c4cbe189039ba833e0da500beff68498 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 27 Dec 2016 14:37:48 +0000 Subject: [PATCH 02/13] Threaded comments will now be transmitted --- include/diaspora.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 77ca376b7d..9b00f6ce6a 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1145,16 +1145,20 @@ class Diaspora { * * @param string $author Author handle * @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 */ - 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)); - if ($r) + if (dbm::is_result($r)) { return $r[0]["uri"]; - else + } elseif (!$onlyfound) { return $author.":".$guid; + } + + return ""; } /** @@ -1196,6 +1200,13 @@ class Diaspora { $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); if (!$contact) { return false; @@ -1240,7 +1251,12 @@ class Diaspora { $datarray["type"] = "remote-comment"; $datarray["verb"] = ACTIVITY_POST; $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"] = $xml; From ca0e6cba02e5d5f8971f129bfecc85ef0284d467 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 28 Dec 2016 13:30:55 +0000 Subject: [PATCH 03/13] Relaying of Diaspora comments now work with the new fields as well. --- include/diaspora.php | 43 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 9b00f6ce6a..2bbd1f4ab0 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -3465,26 +3465,13 @@ class Diaspora { $message = self::construct_like($r[0], $contact); $message["author_signature"] = self::signature($contact, $message); - // In the future we will store the signature more flexible to support new fields. - // Right now we cannot change this since old Friendica versions (prior to 3.5) can only handle this format. - // (We are transmitting this data here via DFRN) - - $signed_text = $message["positive"].";".$message["guid"].";".$message["target_type"].";". - $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"]) + // We now store the signature more flexible to dynamically support new fields. + // This will break Diaspora compatibility with Friendica versions prior to 3.5. + q("INSERT INTO `sign` (`iid`,`signed_text`) VALUES (%d,'%s')", + intval($message_id), + dbesc(json_encode($message)) ); - // 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'); return true; } @@ -3511,25 +3498,13 @@ class Diaspora { $message = self::construct_comment($item, $contact); $message["author_signature"] = self::signature($contact, $message); - // In the future we will store the signature more flexible to support new fields. - // Right now we cannot change this since old Friendica versions (prior to 3.5) can only handle this format. - // (We are transmitting this data here via DFRN) - $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')", + // We now store the signature more flexible to dynamically support new fields. + // This will break Diaspora compatibility with Friendica versions prior to 3.5. + q("INSERT INTO `sign` (`iid`,`signed_text`) VALUES (%d,'%s')", intval($message_id), - dbesc($signed_text), - dbesc($message["author_signature"]), - dbesc($message["diaspora_handle"]) + dbesc(json_encode($message)) ); - // 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'); return true; } From 483f34c4ce7cf9a9b0404488d8a5c46a6532f29b Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 29 Dec 2016 03:13:57 +0000 Subject: [PATCH 04/13] We now transmit event data as well --- include/diaspora.php | 73 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 10 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 2bbd1f4ab0..d3038e62ce 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1914,18 +1914,18 @@ class Diaspora { * * @return string The XML */ - private function construct_new_friend_object($contact) { - $objtype = ACTIVITY_OBJ_PERSON; - $link = ''."\n". - ''."\n"; + private function construct_new_friend_object($contact) { + $objtype = ACTIVITY_OBJ_PERSON; + $link = ''."\n". + ''."\n"; - $xmldata = array("object" => array("type" => $objtype, - "title" => $contact["name"], - "id" => $contact["url"]."/".$contact["name"], - "link" => $link)); + $xmldata = array("object" => array("type" => $objtype, + "title" => $contact["name"], + "id" => $contact["url"]."/".$contact["name"], + "link" => $link)); - return xml::from_array($xmldata, $xml, true); - } + return xml::from_array($xmldata, $xml, true); + } /** * @brief Processes incoming sharing notification @@ -2939,6 +2939,52 @@ class Diaspora { 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 `start`, `finish`, `summary`, `desc`, `location`, `adjust` FROM `event` WHERE `id` = %d", intval($event_id)); + if (!dbm::is_result($r)) { + return array(); + } + + $eventdata = array(); + + /// @todo Timezone in start und end? + + if ($r[0]['adjust']) { + $eventdata['timezone'] = 'UTC'; + } else { + $eventdata['timezone'] = date_default_timezone_get(); + } + + if ($r[0]['start']) { + $eventdata['start'] = datetime_convert("UTC", "UTC", $r[0]['start'], 'Y-m-d\TH:i:s\Z'); + } + if ($r[0]['finish']) { + $eventdata['end'] = datetime_convert("UTC", "UTC", $r[0]['finish'], 'Y-m-d\TH:i:s\Z'); + } + if ($r[0]['summary']) { + $eventdata['summary'] = html_entity_decode(bb2diaspora($r[0]['summary'])); + } + if ($r[0]['desc']) { + $eventdata['description'] = html_entity_decode(bb2diaspora($r[0]['desc'])); + } + if ($r[0]['location']) { + $location = array(); + $location["address"] = html_entity_decode(bb2diaspora($r[0]['location'])); + $location["lat"] = 0; + $location["lng"] = 0; + $eventdata['location'] = $location; + } + + return $eventdata; + } + /** * @brief Create a post (status message or reshare) * @@ -3012,6 +3058,13 @@ class Diaspora { unset($message["location"]); } + if ($item['event-id'] > 0) { + $event = self::build_event($item['event-id']); + if (count($event)) { + $message['event'] = $event; + } + } + $type = "status_message"; } return array("type" => $type, "message" => $message); From 9af3f5b0da24e24a74befc0e8feecff0e27e67af Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 29 Dec 2016 17:11:59 +0000 Subject: [PATCH 05/13] Improved loggin --- include/diaspora.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index 2bbd1f4ab0..982274dd1f 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -520,7 +520,7 @@ class Diaspora { $key = self::key($msg["author"]); 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; } } @@ -528,7 +528,7 @@ class Diaspora { $key = self::key($fields->author); 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; } else return true; From 94977cca181c28c2d3616bddb0d983c9630f0083 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 29 Dec 2016 23:27:11 +0000 Subject: [PATCH 06/13] Events are now done. --- include/diaspora.php | 150 +++++++++++++++++++++++++------------------ 1 file changed, 88 insertions(+), 62 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index c5e5fc7323..1e31bae8e5 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -18,6 +18,7 @@ require_once("include/group.php"); require_once("include/xml.php"); require_once("include/datetime.php"); require_once("include/queue_fn.php"); +require_once("include/cache.php"); /** * @brief This class contain functions to create and send Diaspora XML files @@ -87,7 +88,7 @@ class Diaspora { * * @return string the repaired signature */ - private function repair_signature($signature, $handle = "", $level = 1) { + private static function repair_signature($signature, $handle = "", $level = 1) { if ($signature == "") return ($signature); @@ -111,7 +112,7 @@ class Diaspora { * * @return string verified data */ - private function verify_magic_envelope($envelope) { + private static function verify_magic_envelope($envelope) { $basedom = parse_xml_string($envelope, false); @@ -412,7 +413,7 @@ class Diaspora { * * @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); @@ -541,7 +542,7 @@ class Diaspora { * * @return string The public key */ - private function key($handle) { + private static function key($handle) { $handle = strval($handle); logger("Fetching diaspora key for: ".$handle); @@ -560,7 +561,7 @@ class Diaspora { * * @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", dbesc(NETWORK_DIASPORA), @@ -601,7 +602,7 @@ class Diaspora { * * @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) { $r = q("UPDATE `fcontact` SET @@ -734,7 +735,7 @@ class Diaspora { * * @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", intval($uid), dbesc($handle) @@ -765,7 +766,7 @@ class Diaspora { * * @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. // That makes us friends. @@ -804,7 +805,7 @@ class Diaspora { * * @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); if (!$contact) { 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. */ - 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", intval($uid), dbesc($guid) @@ -845,7 +846,7 @@ class Diaspora { * * @param array $item The item array */ - private function fetch_guid($item) { + private static function fetch_guid($item) { preg_replace_callback("&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi", function ($match) use ($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 $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"])) 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 */ - private function store_by_guid($guid, $server, $uid = 0) { + private static function store_by_guid($guid, $server, $uid = 0) { $serverparts = parse_url($server); $server = $serverparts["scheme"]."://".$serverparts["host"]; @@ -933,7 +934,7 @@ class Diaspora { * 'author' => The author handle * '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) return false; @@ -1009,7 +1010,7 @@ class Diaspora { * * @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`, `author-name`, `author-link`, `author-avatar`, `owner-name`, `owner-link`, `owner-avatar` @@ -1055,7 +1056,7 @@ class Diaspora { * 'cid' => contact id * '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", dbesc(normalise_link($person["url"])), intval($uid)); @@ -1093,7 +1094,7 @@ class Diaspora { * * @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)); // Fallback @@ -1123,7 +1124,7 @@ class Diaspora { * * @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 @@ -1188,7 +1189,7 @@ class Diaspora { * * @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)); $parent_guid = notags(unxmlify($data->parent_guid)); $text = unxmlify($data->text); @@ -1304,7 +1305,7 @@ class Diaspora { * * @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)); $subject = notags(unxmlify($data->subject)); $author = notags(unxmlify($data->author)); @@ -1429,7 +1430,7 @@ class Diaspora { * * @return bool Success */ - private function receive_conversation($importer, $msg, $data) { + private static function receive_conversation($importer, $msg, $data) { $guid = notags(unxmlify($data->guid)); $subject = notags(unxmlify($data->subject)); $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at))); @@ -1495,7 +1496,7 @@ class Diaspora { * * @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'); $ulink = "[url=".$contact["url"]."]".$contact["name"]."[/url]"; @@ -1513,7 +1514,7 @@ class Diaspora { * * @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; $link = ''; $parent_body = $parent_item["body"]; @@ -1537,7 +1538,7 @@ class Diaspora { * * @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)); $guid = notags(unxmlify($data->guid)); $parent_type = notags(unxmlify($data->parent_type)); @@ -1634,7 +1635,7 @@ class Diaspora { * * @return bool Success? */ - private function receive_message($importer, $data) { + private static function receive_message($importer, $data) { $guid = notags(unxmlify($data->guid)); $parent_guid = notags(unxmlify($data->parent_guid)); $text = unxmlify($data->text); @@ -1715,7 +1716,7 @@ class Diaspora { * * @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 return true; } @@ -1728,7 +1729,7 @@ class Diaspora { * * @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 return true; } @@ -1741,7 +1742,7 @@ class Diaspora { * * @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 return true; } @@ -1754,7 +1755,7 @@ class Diaspora { * * @return bool Success */ - private function receive_profile($importer, $data) { + private static function receive_profile($importer, $data) { $author = strtolower(notags(unxmlify($data->author))); $contact = self::contact_by_handle($importer["uid"], $author); @@ -1845,7 +1846,7 @@ class Diaspora { * @param array $importer Array of the importer user * @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(); @@ -1914,7 +1915,7 @@ class Diaspora { * * @return string The XML */ - private function construct_new_friend_object($contact) { + private static function construct_new_friend_object($contact) { $objtype = ACTIVITY_OBJ_PERSON; $link = ''."\n". ''."\n"; @@ -1935,7 +1936,7 @@ class Diaspora { * * @return bool Success */ - private function receive_contact_request($importer, $data) { + private static function receive_contact_request($importer, $data) { $author = unxmlify($data->author); $recipient = unxmlify($data->recipient); @@ -2116,7 +2117,7 @@ class Diaspora { * * @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? $r = q("SELECT `body`, `tag`, `app`, `created`, `object-type`, `uri`, `guid`, @@ -2187,7 +2188,7 @@ class Diaspora { * * @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_guid = notags(unxmlify($data->root_guid)); $guid = notags(unxmlify($data->guid)); @@ -2266,7 +2267,7 @@ class Diaspora { * * @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_guid = notags(unxmlify($data->target_guid)); $author = notags(unxmlify($data->author)); @@ -2322,7 +2323,7 @@ class Diaspora { * * @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)); $contact = self::contact_by_handle($importer["uid"], $sender); @@ -2364,7 +2365,7 @@ class Diaspora { * * @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); $guid = notags(unxmlify($data->guid)); $author = notags(unxmlify($data->author)); @@ -2475,7 +2476,7 @@ class Diaspora { * * @return string the handle in the format user@domain.tld */ - private function my_handle($contact) { + private static function my_handle($contact) { if ($contact["addr"] != "") return $contact["addr"]; @@ -2534,7 +2535,7 @@ class Diaspora { * * @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); @@ -2580,7 +2581,7 @@ class Diaspora { * * @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); @@ -2671,7 +2672,7 @@ class Diaspora { * * @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) $magic_env = self::build_public_message($msg,$user,$contact,$prvkey,$pubkey); @@ -2691,7 +2692,7 @@ class Diaspora { * * @return string The signature */ - private function signature($owner, $message) { + private static function signature($owner, $message) { $sigmsg = $message; unset($sigmsg["author_signature"]); unset($sigmsg["parent_author_signature"]); @@ -2798,7 +2799,7 @@ class Diaspora { * * @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); @@ -2947,36 +2948,49 @@ class Diaspora { * @return array with event data */ private static function build_event($event_id) { - $r = q("SELECT `start`, `finish`, `summary`, `desc`, `location`, `adjust` FROM `event` WHERE `id` = %d", intval($event_id)); + + $r = q("SELECT `uid`, `start`, `finish`, `summary`, `desc`, `location`, `adjust` FROM `event` WHERE `id` = %d", intval($event_id)); if (!dbm::is_result($r)) { return array(); } + $event = $r[0]; + $eventdata = array(); - /// @todo Timezone in start und end? + $r = q("SELECT `timezone` FROM `user` WHERE `uid` = %d", intval($event['uid'])); + if (!dbm::is_result($r)) { + return array(); + } - if ($r[0]['adjust']) { - $eventdata['timezone'] = 'UTC'; + $user = $r[0]; + + if ($event['adjust']) { + $eventdata['timezone'] = $user['timezone']; + + if ($eventdata['timezone'] == "") { + $eventdata['timezone'] = 'UTC'; + } + $mask = 'Y-m-d\TH:i:s\Z'; } else { - $eventdata['timezone'] = date_default_timezone_get(); + $mask = 'Y-m-d\TH:i:s'; } - if ($r[0]['start']) { - $eventdata['start'] = datetime_convert("UTC", "UTC", $r[0]['start'], 'Y-m-d\TH:i:s\Z'); + if ($event['start']) { + $eventdata['start'] = datetime_convert("UTC", "UTC", $event['start'], $mask); } - if ($r[0]['finish']) { - $eventdata['end'] = datetime_convert("UTC", "UTC", $r[0]['finish'], 'Y-m-d\TH:i:s\Z'); + if ($event['finish']) { + $eventdata['end'] = datetime_convert("UTC", "UTC", $event['finish'], $mask); } - if ($r[0]['summary']) { - $eventdata['summary'] = html_entity_decode(bb2diaspora($r[0]['summary'])); + if ($event['summary']) { + $eventdata['summary'] = html_entity_decode(bb2diaspora($event['summary'])); } - if ($r[0]['desc']) { - $eventdata['description'] = html_entity_decode(bb2diaspora($r[0]['desc'])); + if ($event['desc']) { + $eventdata['description'] = html_entity_decode(bb2diaspora($event['desc'])); } - if ($r[0]['location']) { + if ($event['location']) { $location = array(); - $location["address"] = html_entity_decode(bb2diaspora($r[0]['location'])); + $location["address"] = html_entity_decode(bb2diaspora($event['location'])); $location["lat"] = 0; $location["lng"] = 0; $eventdata['location'] = $location; @@ -2997,6 +3011,13 @@ class Diaspora { */ 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); $public = (($item["private"]) ? "false" : "true"); @@ -3067,7 +3088,12 @@ class Diaspora { $type = "status_message"; } - return array("type" => $type, "message" => $message); + + $msg = array("type" => $type, "message" => $message); + + Cache::set($cachekey, $msg, CACHE_QUARTER_HOUR); + + return $msg; } /** @@ -3095,7 +3121,7 @@ class Diaspora { * * @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", dbesc($item["thr-parent"])); @@ -3123,7 +3149,7 @@ class Diaspora { * * @return array The data for a comment */ - private function construct_comment($item, $owner) { + private static function construct_comment($item, $owner) { $p = q("SELECT `guid` FROM `item` WHERE `parent` = %d AND `id` = %d LIMIT 1", intval($item["parent"]), @@ -3188,7 +3214,7 @@ class Diaspora { * * @return string The message */ - private function message_from_signature($item, $signature) { + private static function message_from_signature($item, $signature) { // Split the signed text $signed_parts = explode(";", $signature['signed_text']); From 55ee80338f4e02f9330bfcccccee6ea6e3e2036a Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 30 Dec 2016 03:31:38 +0000 Subject: [PATCH 07/13] Events are now shared with Diaspora. --- boot.php | 2 +- database.sql | 3 ++- include/dbstructure.php | 1 + include/diaspora.php | 34 ++++++++++++++++++++++++++-------- include/event.php | 9 +++++---- update.php | 2 +- 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/boot.php b/boot.php index e480f8e3ac..aad8813766 100644 --- a/boot.php +++ b/boot.php @@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica'); define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_VERSION', '3.5.1-dev' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); -define ( 'DB_UPDATE_VERSION', 1210 ); +define ( 'DB_UPDATE_VERSION', 1211 ); /** * @brief Constant with a HTML line break. diff --git a/database.sql b/database.sql index 3eb70b4511..2e83c33a64 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- 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` ( `id` int(11) NOT NULL auto_increment, + `guid` varchar(255) NOT NULL DEFAULT '', `uid` int(11) NOT NULL DEFAULT 0, `cid` int(11) NOT NULL DEFAULT 0, `uri` varchar(255) NOT NULL DEFAULT '', diff --git a/include/dbstructure.php b/include/dbstructure.php index 3ff9efee79..4a8bac1982 100644 --- a/include/dbstructure.php +++ b/include/dbstructure.php @@ -622,6 +622,7 @@ function db_definition($charset) { $database["event"] = array( "fields" => array( "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"), "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), diff --git a/include/diaspora.php b/include/diaspora.php index 1e31bae8e5..eda1b090d5 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -2949,7 +2949,7 @@ class Diaspora { */ private static function build_event($event_id) { - $r = q("SELECT `uid`, `start`, `finish`, `summary`, `desc`, `location`, `adjust` FROM `event` WHERE `id` = %d", intval($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(); } @@ -2965,22 +2965,37 @@ class Diaspora { $user = $r[0]; - if ($event['adjust']) { + $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 + $eventdata["all_day"] = "false"; + + if (!$event['adjust']) { $eventdata['timezone'] = $user['timezone']; if ($eventdata['timezone'] == "") { $eventdata['timezone'] = 'UTC'; } - $mask = 'Y-m-d\TH:i:s\Z'; - } else { - $mask = 'Y-m-d\TH:i:s'; } if ($event['start']) { - $eventdata['start'] = datetime_convert("UTC", "UTC", $event['start'], $mask); + $eventdata['start'] = datetime_convert($eventdata['timezone'], "UTC", $event['start'], $mask); } - if ($event['finish']) { - $eventdata['end'] = datetime_convert("UTC", "UTC", $event['finish'], $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'])); @@ -3083,6 +3098,9 @@ class Diaspora { $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'] = ''; } } diff --git a/include/event.php b/include/event.php index 4abe3ffef5..791c331bbb 100644 --- a/include/event.php +++ b/include/event.php @@ -246,6 +246,7 @@ function event_store($arr) { $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['private'] = ((x($arr,'private')) ? intval($arr['private']) : 0); + $arr['guid'] = get_guid(32); if($arr['cid']) $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']); return $item_id; - } - else { + } else { // 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`) - 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['cid']), + dbesc($arr['guid']), dbesc($arr['uri']), dbesc($arr['created']), dbesc($arr['edited']), diff --git a/update.php b/update.php index 948e10f27e..3bd9cbe610 100644 --- a/update.php +++ b/update.php @@ -1,6 +1,6 @@ Date: Fri, 30 Dec 2016 10:03:02 +0000 Subject: [PATCH 08/13] Standard stuff --- include/diaspora.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index eda1b090d5..72b9537416 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -1173,10 +1173,11 @@ class Diaspora { 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)) + if (dbm::is_result($r)) { return $r[0]["guid"]; - else + } else { return false; + } } /** @@ -2980,7 +2981,7 @@ class Diaspora { $mask = 'Y-m-d\TH:i:s\Z'; - /// @todo + /// @todo - establish "all day" events in Friendica $eventdata["all_day"] = "false"; if (!$event['adjust']) { From d2df464d8c4fe0dab390c3016f651f423bd3b9a4 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 30 Dec 2016 21:48:09 +0100 Subject: [PATCH 09/13] added curly braces + fixed indenting according to code review by Hypolite Signed-off-by: Roland Haeder --- include/follow.php | 10 +++----- include/items.php | 11 ++++++--- mod/contacts.php | 46 ++++++++++++++++++----------------- mod/profile.php | 12 +++------ view/theme/quattro/config.php | 6 ++--- 5 files changed, 42 insertions(+), 43 deletions(-) diff --git a/include/follow.php b/include/follow.php index 8d80538e0c..3045191077 100644 --- a/include/follow.php +++ b/include/follow.php @@ -110,12 +110,10 @@ function new_contact($uid,$url,$interactive = false) { // NOTREACHED } - } else { - if (get_config('system','dfrn_only')) { - $result['message'] = t('This site is not configured to allow communications with other networks.') . EOL; - $result['message'] != t('No compatible communication protocols or feeds were discovered.') . EOL; - return $result; - } + } elseif (get_config('system','dfrn_only')) { + $result['message'] = t('This site is not configured to allow communications with other networks.') . EOL; + $result['message'] != t('No compatible communication protocols or feeds were discovered.') . EOL; + return $result; } // This extra param just confuses things, remove it diff --git a/include/items.php b/include/items.php index 8d95c35529..fa4f3290b1 100644 --- a/include/items.php +++ b/include/items.php @@ -955,12 +955,14 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa $r = q('SELECT * FROM `item` WHERE `id` = %d', intval($current_post)); if ((dbm::is_result($r)) && (count($r) == 1)) { - if ($notify) + if ($notify) { call_hooks('post_local_end', $r[0]); - else + } else { call_hooks('post_remote_end', $r[0]); - } else + } + } else { logger('item_store: new item not found in DB, id ' . $current_post); + } } if ($arr['parent-uri'] === $arr['uri']) { @@ -994,8 +996,9 @@ function item_store($arr,$force_parent = false, $notify = false, $dontcache = fa check_item_notification($current_post, $uid); - if ($notify) + if ($notify) { proc_run(PRIORITY_HIGH, "include/notifier.php", $notify_type, $current_post); + } return $current_post; } diff --git a/mod/contacts.php b/mod/contacts.php index 26dfe06078..38e0992257 100644 --- a/mod/contacts.php +++ b/mod/contacts.php @@ -37,34 +37,36 @@ function contacts_init(App &$a) { } if ($contact_id) { - $a->data['contact'] = $r[0]; + $a->data['contact'] = $r[0]; - if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) { - $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']); - } else { - $networkname = ''; - } + if (($a->data['contact']['network'] != "") AND ($a->data['contact']['network'] != NETWORK_DFRN)) { + $networkname = format_network_name($a->data['contact']['network'],$a->data['contact']['url']); + } else { + $networkname = ''; + } - $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array( - '$name' => htmlentities($a->data['contact']['name']), - '$photo' => $a->data['contact']['photo'], - '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/".$a->data['contact']['id'] : $a->data['contact']['url'], - '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""), - '$network_name' => $networkname, - '$network' => t('Network:'), - '$account_type' => account_type($a->data['contact']) - )); - $finpeople_widget = ''; - $follow_widget = ''; - $networks_widget = ''; - } - else { + /// @TODO Add nice spaces + $vcard_widget = replace_macros(get_markup_template("vcard-widget.tpl"),array( + '$name' => htmlentities($a->data['contact']['name']), + '$photo' => $a->data['contact']['photo'], + '$url' => ($a->data['contact']['network'] == NETWORK_DFRN) ? "redir/".$a->data['contact']['id'] : $a->data['contact']['url'], + '$addr' => (($a->data['contact']['addr'] != "") ? ($a->data['contact']['addr']) : ""), + '$network_name' => $networkname, + '$network' => t('Network:'), + '$account_type' => account_type($a->data['contact']) + )); + + $finpeople_widget = ''; + $follow_widget = ''; + $networks_widget = ''; + } else { $vcard_widget = ''; $networks_widget .= networks_widget('contacts',$_GET['nets']); - if (isset($_GET['add'])) + if (isset($_GET['add'])) { $follow_widget = follow_widget($_GET['add']); - else + } else { $follow_widget = follow_widget(); + } $findpeople_widget .= findpeople_widget(); } diff --git a/mod/profile.php b/mod/profile.php index 32539758e2..32d3985b7f 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -111,10 +111,8 @@ function profile_content(&$a, $update = 0) { if ($update) { // Ensure we've got a profile owner if updating. $a->profile['profile_uid'] = $update; - } else { - if ($a->profile['profile_uid'] == local_user()) { - nav_set_selected('home'); - } + } elseif ($a->profile['profile_uid'] == local_user()) { + nav_set_selected('home'); } $contact = null; @@ -158,12 +156,12 @@ function profile_content(&$a, $update = 0) { } if (! $update) { - if (x($_GET,'tab')) + if (x($_GET,'tab')) { $tab = notags(trim($_GET['tab'])); + } $o.=profile_tabs($a, $is_owner, $a->profile['nickname']); - if ($tab === 'profile') { $o .= advanced_profile($a); call_hooks('profile_advanced',$o); @@ -201,14 +199,12 @@ function profile_content(&$a, $update = 0) { $o .= status_editor($a,$x); } - } /** * Get permissions SQL - if $remote_contact is true, our remote user has been pre-verified and we already have fetched his/her groups */ - $sql_extra = item_permissions_sql($a->profile['profile_uid'],$remote_contact,$groups); diff --git a/view/theme/quattro/config.php b/view/theme/quattro/config.php index 32f71db015..6c80afdc22 100644 --- a/view/theme/quattro/config.php +++ b/view/theme/quattro/config.php @@ -33,7 +33,7 @@ function theme_admin(App &$a){ $align = get_config('quattro', 'align' ); $color = get_config('quattro', 'color' ); $tfs = get_config("quattro","tfs"); - $pfs = get_config("quattro","pfs"); + $pfs = get_config("quattro","pfs"); return quattro_form($a,$align, $color, $tfs, $pfs); } @@ -69,8 +69,8 @@ function quattro_form(App &$a, $align, $color, $tfs, $pfs){ '$title' => t("Theme settings"), '$align' => array('quattro_align', t('Alignment'), $align, '', array('left'=>t('Left'), 'center'=>t('Center'))), '$color' => array('quattro_color', t('Color scheme'), $color, '', $colors), - '$pfs' => array('quattro_pfs', t('Posts font size'), $pfs), - '$tfs' => array('quattro_tfs',t('Textareas font size'), $tfs), + '$pfs' => array('quattro_pfs', t('Posts font size'), $pfs), + '$tfs' => array('quattro_tfs',t('Textareas font size'), $tfs), )); return $o; } From 7cf70b64b80be6ec06f4b68679ecf6995b0639f3 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 30 Dec 2016 22:31:21 +0000 Subject: [PATCH 10/13] We now send the participation message as well. --- include/delivery.php | 9 --------- include/diaspora.php | 44 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/include/delivery.php b/include/delivery.php index f7245942a9..e9f4264641 100644 --- a/include/delivery.php +++ b/include/delivery.php @@ -518,15 +518,6 @@ function delivery_run(&$argv, &$argc){ if (!$contact['pubkey'] && !$public_message) 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)) { // top-level retraction logger('diaspora retract: '.$loc); diff --git a/include/diaspora.php b/include/diaspora.php index 72b9537416..a6e6e5cf76 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -3160,6 +3160,45 @@ class Diaspora { "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 * @@ -3209,7 +3248,10 @@ class Diaspora { */ 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($item['verb'] === ACTIVITY_LIKE) { $message = self::construct_like($item, $owner); $type = "like"; } else { From 66902c7956eedba02ea54aea6ea7aa417344ffbb Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 30 Dec 2016 22:40:30 +0000 Subject: [PATCH 11/13] We now also transmit Dislikes --- include/diaspora.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/diaspora.php b/include/diaspora.php index a6e6e5cf76..edc2f3c85f 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -3150,7 +3150,11 @@ class Diaspora { $parent = $p[0]; $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, "guid" => $item["guid"], @@ -3251,7 +3255,7 @@ class Diaspora { if (in_array($item['verb'], array(ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE))) { $message = self::construct_attend($item, $owner); $type = "event_participation"; - } elseif($item['verb'] === ACTIVITY_LIKE) { + } elseif (in_array($item["verb"], array(ACTIVITY_LIKE, ACTIVITY_DISLIKE))) { $message = self::construct_like($item, $owner); $type = "like"; } else { From 93666b5a8d292725f6d33fc191de4aa27c1463e1 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 30 Dec 2016 22:54:16 +0000 Subject: [PATCH 12/13] Disable some features --- object/Item.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/object/Item.php b/object/Item.php index 4b3dfd5642..8340009a9b 100644 --- a/object/Item.php +++ b/object/Item.php @@ -334,7 +334,9 @@ class Item extends BaseObject { } // 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); $tagger = ''; } @@ -347,18 +349,12 @@ class Item extends BaseObject { unset($buttons["like"]); } - // Disabled for testing purposes - - // Diaspora isn't able to do likes on comments - but red does - //if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment') AND - // !Diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) { - // unset($buttons["like"]); - //} - - // Diaspora doesn't has multithreaded comments - //if (($item["item_network"] == NETWORK_DIASPORA) AND ($indent == 'comment')) { - // unset($comment); - //} + // 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 + !Diaspora::is_redmatrix($item["owner-link"]) AND isset($buttons["like"])) { + unset($buttons["like"]); + } // 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"])) { From 4053499c38cc4191fd4bf4724d17c968ecd2f756 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 30 Dec 2016 23:18:31 +0000 Subject: [PATCH 13/13] Enable caching wirh comments --- include/diaspora.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/diaspora.php b/include/diaspora.php index edc2f3c85f..fbfc497b59 100644 --- a/include/diaspora.php +++ b/include/diaspora.php @@ -3213,6 +3213,13 @@ class Diaspora { */ 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", intval($item["parent"]), intval($item["parent"]) @@ -3237,6 +3244,9 @@ class Diaspora { 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); }