- DiasporaFetchGuid($datarray);
- $message_id = item_store($datarray);
-
- return;
-
-}
-
-
-function diaspora_asphoto($importer,$xml,$msg) {
- logger('diaspora_asphoto called');
-
- $a = get_app();
- $guid = notags(unxmlify($xml->guid));
- $diaspora_handle = notags(unxmlify($xml->diaspora_handle));
-
- if($diaspora_handle != $msg['author']) {
- logger('diaspora_post: Potential forgery. Message handle is not the same as envelope sender.');
- return 202;
- }
+ /**
+ * @brief Creates the body for a "like" message
+ *
+ * @param array $contact The contact that send us the "like"
+ * @param array $parent_item The item array of the parent item
+ * @param string $guid message guid
+ *
+ * @return string the body
+ */
+ private 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]";
+ $alink = "[url=".$parent_item["author-link"]."]".$parent_item["author-name"]."[/url]";
+ $plink = "[url=".App::get_baseurl()."/display/".urlencode($guid)."]".t("status")."[/url]";
+
+ return sprintf($bodyverb, $ulink, $alink, $plink);
+ }
+
+ /**
+ * @brief Creates a XML object for a "like"
+ *
+ * @param array $importer Array of the importer user
+ * @param array $parent_item The item array of the parent item
+ *
+ * @return string The XML
+ */
+ private function construct_like_object($importer, $parent_item) {
+ $objtype = ACTIVITY_OBJ_NOTE;
+ $link = '<link rel="alternate" type="text/html" href="'.App::get_baseurl()."/display/".$importer["nickname"]."/".$parent_item["id"].'" />';
+ $parent_body = $parent_item["body"];
+
+ $xmldata = array("object" => array("type" => $objtype,
+ "local" => "1",
+ "id" => $parent_item["uri"],
+ "link" => $link,
+ "title" => "",
+ "content" => $parent_body));
+
+ return xml::from_array($xmldata, $xml, true);
+ }
+
+ /**
+ * @brief Processes "like" messages
+ *
+ * @param array $importer Array of the importer user
+ * @param string $sender The sender of the message
+ * @param object $data The message object
+ *
+ * @return int The message id of the generated like or "false" if there was an error
+ */
+ private function receive_like($importer, $sender, $data) {
+ $positive = notags(unxmlify($data->positive));
+ $guid = notags(unxmlify($data->guid));
+ $parent_type = notags(unxmlify($data->parent_type));
+ $parent_guid = notags(unxmlify($data->parent_guid));
+ $author = notags(unxmlify($data->author));
+
+ // likes on comments aren't supported by Diaspora - only on posts
+ // But maybe this will be supported in the future, so we will accept it.
+ if (!in_array($parent_type, array("Post", "Comment")))
+ return false;