3 * @file include/diaspora.php
4 * @brief The implementation of the diaspora protocol
7 require_once("include/items.php");
8 require_once("include/bb2diaspora.php");
9 require_once("include/Scrape.php");
10 require_once("include/Contact.php");
11 require_once("include/Photo.php");
12 require_once("include/socgraph.php");
13 require_once("include/group.php");
14 require_once("include/api.php");
17 * @brief This class contain functions to work with XML data
21 function from_array($array, &$xml) {
23 if (!is_object($xml)) {
24 foreach($array as $key => $value) {
25 $root = new SimpleXMLElement("<".$key."/>");
26 array_to_xml($value, $root);
28 $dom = dom_import_simplexml($root)->ownerDocument;
29 $dom->formatOutput = true;
30 return $dom->saveXML();
34 foreach($array as $key => $value) {
35 if (!is_array($value) AND !is_numeric($key))
36 $xml->addChild($key, $value);
37 elseif (is_array($value))
38 array_to_xml($value, $xml->addChild($key));
42 function copy(&$source, &$target, $elementname) {
43 if (count($source->children()) == 0)
44 $target->addChild($elementname, $source);
46 $child = $target->addChild($elementname);
47 foreach ($source->children() AS $childfield => $childentry)
48 self::copy($childentry, $child, $childfield);
54 * @brief This class contain functions to create and send Diaspora XML files
60 * @brief Dispatches public messages and find the fitting receivers
62 * @param array $msg The post that will be dispatched
64 * @return bool Was the message accepted?
66 public static function dispatch_public($msg) {
68 $enabled = intval(get_config("system", "diaspora_enabled"));
70 logger("diaspora is disabled");
74 // Use a dummy importer to import the data for the public copy
75 $importer = array("uid" => 0, "page-flags" => PAGE_FREELOVE);
76 $item_id = self::dispatch($importer,$msg);
78 // Now distribute it to the followers
79 $r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN
80 (SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s')
81 AND NOT `account_expired` AND NOT `account_removed`",
82 dbesc(NETWORK_DIASPORA),
87 logger("delivering to: ".$rr["username"]);
88 self::dispatch($rr,$msg);
91 logger("No subscribers for ".$msg["author"]." ".print_r($msg, true));
97 * @brief Dispatches the different message types to the different functions
99 * @param array $importer Array of the importer user
100 * @param array $msg The post that will be dispatched
102 * @return bool Was the message accepted?
104 public static function dispatch($importer, $msg) {
106 // The sender is the handle of the contact that sent the message.
107 // This will often be different with relayed messages (for example "like" and "comment")
108 $sender = $msg["author"];
110 if (!diaspora::valid_posting($msg, $fields)) {
111 logger("Invalid posting");
115 $type = $fields->getName();
118 case "account_deletion": // Done
120 return self::receive_account_deletion($importer, $fields);
122 case "comment": // Done
124 return self::receive_comment($importer, $sender, $fields);
126 case "conversation": // Done
128 return self::receive_conversation($importer, $msg, $fields);
132 return self::receive_like($importer, $sender, $fields);
134 case "message": // Done
136 return self::receive_message($importer, $fields);
138 case "participation": // Not implemented
139 return self::receive_participation($importer, $fields);
141 case "photo": // Not needed
142 return self::receive_photo($importer, $fields);
144 case "poll_participation": // Not implemented
145 return self::receive_poll_participation($importer, $fields);
147 case "profile": // Done
149 return self::receive_profile($importer, $fields);
153 return self::receive_request($importer, $fields);
155 case "reshare": // Done
157 return self::receive_reshare($importer, $fields);
159 case "retraction": // Done
161 return self::receive_retraction($importer, $sender, $fields);
163 case "status_message": // Done
165 return self::receive_status_message($importer, $fields);
168 logger("Unknown message type ".$type);
176 * @brief Checks if a posting is valid and fetches the data fields.
178 * This function does not only check the signature.
179 * It also does the conversion between the old and the new diaspora format.
181 * @param array $msg Array with the XML, the sender handle and the sender signature
182 * @param object $fields SimpleXML object that contains the posting when it is valid
184 * @return bool Is the posting valid?
186 private function valid_posting($msg, &$fields) {
188 $data = parse_xml_string($msg["message"], false);
190 if (!is_object($data))
193 $first_child = $data->getName();
195 // Is this the new or the old version?
196 if ($data->getName() == "XML") {
198 foreach ($data->post->children() as $child)
205 $type = $element->getName();
208 // All retractions are handled identically from now on.
209 // In the new version there will only be "retraction".
210 if (in_array($type, array("signed_retraction", "relayable_retraction")))
211 $type = "retraction";
213 $fields = new SimpleXMLElement("<".$type."/>");
217 foreach ($element->children() AS $fieldname => $entry) {
219 // Translation for the old XML structure
220 if ($fieldname == "diaspora_handle")
221 $fieldname = "author";
223 if ($fieldname == "participant_handles")
224 $fieldname = "participants";
226 if (in_array($type, array("like", "participation"))) {
227 if ($fieldname == "target_type")
228 $fieldname = "parent_type";
231 if ($fieldname == "sender_handle")
232 $fieldname = "author";
234 if ($fieldname == "recipient_handle")
235 $fieldname = "recipient";
237 if ($fieldname == "root_diaspora_id")
238 $fieldname = "root_author";
240 if ($type == "retraction") {
241 if ($fieldname == "post_guid")
242 $fieldname = "target_guid";
244 if ($fieldname == "type")
245 $fieldname = "target_type";
249 if ($fieldname == "author_signature")
250 $author_signature = base64_decode($entry);
251 elseif ($fieldname == "parent_author_signature")
252 $parent_author_signature = base64_decode($entry);
253 elseif ($fieldname != "target_author_signature") {
254 if ($signed_data != "") {
256 $signed_data_parent .= ";";
259 $signed_data .= $entry;
261 if (!in_array($fieldname, array("parent_author_signature", "target_author_signature")) OR
262 ($orig_type == "relayable_retraction"))
263 xml::copy($entry, $fields, $fieldname);
266 // This is something that shouldn't happen at all.
267 if (in_array($type, array("status_message", "reshare", "profile")))
268 if ($msg["author"] != $fields->author) {
269 logger("Message handle is not the same as envelope sender. Quitting this message.");
273 // Only some message types have signatures. So we quit here for the other types.
274 if (!in_array($type, array("comment", "message", "like")))
277 // No author_signature? This is a must, so we quit.
278 if (!isset($author_signature))
281 if (isset($parent_author_signature)) {
282 $key = self::get_key($msg["author"]);
284 if (!rsa_verify($signed_data, $parent_author_signature, $key, "sha256"))
288 $key = self::get_key($fields->author);
290 return rsa_verify($signed_data, $author_signature, $key, "sha256");
294 * @brief Fetches the public key for a given handle
296 * @param string $handle The handle
298 * @return string The public key
300 private function get_key($handle) {
301 logger("Fetching diaspora key for: ".$handle);
303 $r = self::get_person_by_handle($handle);
311 * @brief Fetches data for a given handle
313 * @param string $handle The handle
315 * @return array the queried data
317 private function get_person_by_handle($handle) {
319 $r = q("SELECT * FROM `fcontact` WHERE `network` = '%s' AND `addr` = '%s' LIMIT 1",
320 dbesc(NETWORK_DIASPORA),
325 logger("In cache ".print_r($r,true), LOGGER_DEBUG);
327 // update record occasionally so it doesn't get stale
328 $d = strtotime($person["updated"]." +00:00");
329 if ($d < strtotime("now - 14 days"))
333 if (!$person OR $update) {
334 logger("create or refresh", LOGGER_DEBUG);
335 $r = probe_url($handle, PROBE_DIASPORA);
337 // Note that Friendica contacts will return a "Diaspora person"
338 // if Diaspora connectivity is enabled on their server
339 if ($r AND ($r["network"] === NETWORK_DIASPORA)) {
340 self::add_fcontact($r, $update);
348 * @brief Updates the fcontact table
350 * @param array $arr The fcontact data
351 * @param bool $update Update or insert?
353 * @return string The id of the fcontact entry
355 private function add_fcontact($arr, $update = false) {
356 /// @todo Remove this function from include/network.php
359 $r = q("UPDATE `fcontact` SET
372 WHERE `url` = '%s' AND `network` = '%s'",
374 dbesc($arr["photo"]),
375 dbesc($arr["request"]),
378 dbesc($arr["batch"]),
379 dbesc($arr["notify"]),
381 dbesc($arr["confirm"]),
382 dbesc($arr["alias"]),
383 dbesc($arr["pubkey"]),
384 dbesc(datetime_convert()),
386 dbesc($arr["network"])
389 $r = q("INSERT INTO `fcontact` (`url`,`name`,`photo`,`request`,`nick`,`addr`,
390 `batch`, `notify`,`poll`,`confirm`,`network`,`alias`,`pubkey`,`updated`)
391 VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
394 dbesc($arr["photo"]),
395 dbesc($arr["request"]),
398 dbesc($arr["batch"]),
399 dbesc($arr["notify"]),
401 dbesc($arr["confirm"]),
402 dbesc($arr["network"]),
403 dbesc($arr["alias"]),
404 dbesc($arr["pubkey"]),
405 dbesc(datetime_convert())
412 private function get_contact_by_handle($uid, $handle) {
413 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `addr` = '%s' LIMIT 1",
421 $handle_parts = explode("@", $handle);
422 $nurl_sql = "%%://".$handle_parts[1]."%%/profile/".$handle_parts[0];
423 $r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `nurl` LIKE '%s' LIMIT 1",
434 private function post_allow($importer, $contact, $is_comment = false) {
436 // perhaps we were already sharing with this person. Now they're sharing with us.
437 // That makes us friends.
438 // Normally this should have handled by getting a request - but this could get lost
439 if($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) {
440 q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d",
441 intval(CONTACT_IS_FRIEND),
442 intval($contact["id"]),
443 intval($importer["uid"])
445 $contact["rel"] = CONTACT_IS_FRIEND;
446 logger("defining user ".$contact["nick"]." as friend");
449 if(($contact["blocked"]) || ($contact["readonly"]) || ($contact["archive"]))
451 if($contact["rel"] == CONTACT_IS_SHARING || $contact["rel"] == CONTACT_IS_FRIEND)
453 if($contact["rel"] == CONTACT_IS_FOLLOWER)
454 if(($importer["page-flags"] == PAGE_COMMUNITY) OR $is_comment)
457 // Messages for the global users are always accepted
458 if ($importer["uid"] == 0)
464 private function get_allowed_contact_by_handle($importer, $handle, $is_comment = false) {
465 $contact = self::get_contact_by_handle($importer["uid"], $handle);
467 logger("A Contact for handle ".$handle." and user ".$importer["uid"]." was not found");
471 if (!self::post_allow($importer, $contact, false)) {
472 logger("The handle: ".$handle." is not allowed to post to user ".$importer["uid"]);
478 private function message_exists($uid, $guid) {
479 $r = q("SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
485 logger("message ".$guid." already exists for user ".$uid);
492 private function fetch_guid($item) {
493 preg_replace_callback("&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi",
494 function ($match) use ($item){
495 return(self::fetch_guid_sub($match, $item));
499 private function fetch_guid_sub($match, $item) {
500 if (!self::store_by_guid($match[1], $item["author-link"]))
501 self::store_by_guid($match[1], $item["owner-link"]);
504 private function store_by_guid($guid, $server, $uid = 0) {
505 $serverparts = parse_url($server);
506 $server = $serverparts["scheme"]."://".$serverparts["host"];
508 logger("Trying to fetch item ".$guid." from ".$server, LOGGER_DEBUG);
510 $msg = self::fetch_message($guid, $server);
515 logger("Successfully fetched item ".$guid." from ".$server, LOGGER_DEBUG);
517 // Now call the dispatcher
518 return self::dispatch_public($msg);
521 private function fetch_message($guid, $server, $level = 0) {
526 // This will work for Diaspora and newer Friendica servers
527 $source_url = $server."/p/".$guid.".xml";
528 $x = fetch_url($source_url);
532 $source_xml = parse_xml_string($x, false);
534 if (!is_object($source_xml))
537 if ($source_xml->post->reshare) {
538 // Reshare of a reshare - old Diaspora version
539 return self::fetch_message($source_xml->post->reshare->root_guid, $server, ++$level);
540 } elseif ($source_xml->getName() == "reshare") {
541 // Reshare of a reshare - new Diaspora version
542 return self::fetch_message($source_xml->root_guid, $server, ++$level);
545 // Fetch the author - for the old and the new Diaspora version
546 if ($source_xml->post->status_message->diaspora_handle)
547 $author = (string)$source_xml->post->status_message->diaspora_handle;
548 elseif ($source_xml->author)
549 $author = (string)$source_xml->author;
554 $msg = array("message" => $x, "author" => $author);
556 // We don't really need this, but until the work is unfinished we better will keep this
557 $msg["key"] = self::get_key($msg["author"]);
562 private function fetch_parent_item($uid, $guid, $author, $contact) {
563 $r = q("SELECT `id`, `body`, `wall`, `uri`, `private`, `origin`,
564 `author-name`, `author-link`, `author-avatar`,
565 `owner-name`, `owner-link`, `owner-avatar`
566 FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
567 intval($uid), dbesc($guid));
570 $result = self::store_by_guid($guid, $contact["url"], $uid);
573 $person = self::get_person_by_handle($author);
574 $result = self::store_by_guid($guid, $person["url"], $uid);
578 logger("Fetched missing item ".$guid." - result: ".$result, LOGGER_DEBUG);
580 $r = q("SELECT `id`, `body`, `wall`, `uri`, `private`, `origin`,
581 `author-name`, `author-link`, `author-avatar`,
582 `owner-name`, `owner-link`, `owner-avatar`
583 FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
584 intval($uid), dbesc($guid));
589 logger("parent item not found: parent: ".$guid." item: ".$guid);
595 private function get_author_contact_by_url($contact, $person, $uid) {
597 $r = q("SELECT `id`, `network` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
598 dbesc(normalise_link($person["url"])), intval($uid));
601 $network = $r[0]["network"];
603 $cid = $contact["id"];
604 $network = NETWORK_DIASPORA;
607 return (array("cid" => $cid, "network" => $network));
610 public static function is_redmatrix($url) {
611 return(strstr($url, "/channel/"));
614 private function plink($addr, $guid) {
615 $r = q("SELECT `url`, `nick`, `network` FROM `fcontact` WHERE `addr`='%s' LIMIT 1", dbesc($addr));
619 return "https://".substr($addr,strpos($addr,"@")+1)."/posts/".$guid;
621 // Friendica contacts are often detected as Diaspora contacts in the "fcontact" table
622 // So we try another way as well.
623 $s = q("SELECT `network` FROM `gcontact` WHERE `nurl`='%s' LIMIT 1", dbesc(normalise_link($r[0]["url"])));
625 $r[0]["network"] = $s[0]["network"];
627 if ($r[0]["network"] == NETWORK_DFRN)
628 return(str_replace("/profile/".$r[0]["nick"]."/", "/display/".$guid, $r[0]["url"]."/"));
630 if (self::is_redmatrix($r[0]["url"]))
631 return $r[0]["url"]."/?f=&mid=".$guid;
633 return "https://".substr($addr,strpos($addr,"@")+1)."/posts/".$guid;
636 private function receive_account_deletion($importer, $data) {
637 $author = notags(unxmlify($data->author));
639 $contact = self::get_contact_by_handle($importer["uid"], $author);
641 logger("cannot find contact for author: ".$author);
645 // We now remove the contact
646 contact_remove($contact["id"]);
650 private function receive_comment($importer, $sender, $data) {
651 $guid = notags(unxmlify($data->guid));
652 $parent_guid = notags(unxmlify($data->parent_guid));
653 $text = unxmlify($data->text);
654 $author = notags(unxmlify($data->author));
656 $contact = self::get_allowed_contact_by_handle($importer, $sender, true);
660 if (self::message_exists($importer["uid"], $guid))
663 $parent_item = self::fetch_parent_item($importer["uid"], $parent_guid, $author, $contact);
667 $person = self::get_person_by_handle($author);
668 if (!is_array($person)) {
669 logger("unable to find author details");
673 // Fetch the contact id - if we know this contact
674 $author_contact = self::get_author_contact_by_url($contact, $person, $importer["uid"]);
678 $datarray["uid"] = $importer["uid"];
679 $datarray["contact-id"] = $author_contact["cid"];
680 $datarray["network"] = $author_contact["network"];
682 $datarray["author-name"] = $person["name"];
683 $datarray["author-link"] = $person["url"];
684 $datarray["author-avatar"] = ((x($person,"thumb")) ? $person["thumb"] : $person["photo"]);
686 $datarray["owner-name"] = $contact["name"];
687 $datarray["owner-link"] = $contact["url"];
688 $datarray["owner-avatar"] = ((x($contact,"thumb")) ? $contact["thumb"] : $contact["photo"]);
690 $datarray["guid"] = $guid;
691 $datarray["uri"] = $author.":".$guid;
693 $datarray["type"] = "remote-comment";
694 $datarray["verb"] = ACTIVITY_POST;
695 $datarray["gravity"] = GRAVITY_COMMENT;
696 $datarray["parent-uri"] = $parent_item["uri"];
698 $datarray["object-type"] = ACTIVITY_OBJ_COMMENT;
699 $datarray["object"] = json_encode($data);
701 $datarray["body"] = diaspora2bb($text);
703 self::fetch_guid($datarray);
705 $message_id = item_store($datarray);
706 // print_r($datarray);
708 // If we are the origin of the parent we store the original data and notify our followers
709 if($message_id AND $parent_item["origin"]) {
711 // Formerly we stored the signed text, the signature and the author in different fields.
712 // We now store the raw data so that we are more flexible.
713 q("INSERT INTO `sign` (`iid`,`signed_text`) VALUES (%d,'%s')",
715 dbesc(json_encode($data))
719 proc_run("php", "include/notifier.php", "comment-import", $message_id);
725 private function receive_conversation_message($importer, $contact, $data, $msg, $mesg) {
726 $guid = notags(unxmlify($data->guid));
727 $subject = notags(unxmlify($data->subject));
728 $author = notags(unxmlify($data->author));
732 $msg_guid = notags(unxmlify($mesg->guid));
733 $msg_parent_guid = notags(unxmlify($mesg->parent_guid));
734 $msg_parent_author_signature = notags(unxmlify($mesg->parent_author_signature));
735 $msg_author_signature = notags(unxmlify($mesg->author_signature));
736 $msg_text = unxmlify($mesg->text);
737 $msg_created_at = datetime_convert("UTC", "UTC", notags(unxmlify($mesg->created_at)));
739 if ($mesg->diaspora_handle)
740 $msg_author = notags(unxmlify($mesg->diaspora_handle));
741 elseif ($mesg->author)
742 $msg_author = notags(unxmlify($mesg->author));
746 $msg_conversation_guid = notags(unxmlify($mesg->conversation_guid));
748 if($msg_conversation_guid != $guid) {
749 logger("message conversation guid does not belong to the current conversation.");
753 $body = diaspora2bb($msg_text);
754 $message_uri = $msg_author.":".$msg_guid;
756 $author_signed_data = $msg_guid.";".$msg_parent_guid.";".$msg_text.";".unxmlify($mesg->created_at).";".$msg_author.";".$msg_conversation_guid;
758 $author_signature = base64_decode($msg_author_signature);
760 if(strcasecmp($msg_author,$msg["author"]) == 0) {
764 $person = self::get_person_by_handle($msg_author);
766 if (is_array($person) && x($person, "pubkey"))
767 $key = $person["pubkey"];
769 logger("unable to find author details");
774 if (!rsa_verify($author_signed_data, $author_signature, $key, "sha256")) {
775 logger("verification failed.");
779 if($msg_parent_author_signature) {
780 $owner_signed_data = $msg_guid.";".$msg_parent_guid.";".$msg_text.";".unxmlify($mesg->created_at).";".$msg_author.";".$msg_conversation_guid;
782 $parent_author_signature = base64_decode($msg_parent_author_signature);
786 if (!rsa_verify($owner_signed_data, $parent_author_signature, $key, "sha256")) {
787 logger("owner verification failed.");
792 $r = q("SELECT `id` FROM `mail` WHERE `uri` = '%s' LIMIT 1",
796 logger("duplicate message already delivered.", LOGGER_DEBUG);
800 q("INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`)
801 VALUES (%d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
802 intval($importer["uid"]),
804 intval($conversation["id"]),
805 dbesc($person["name"]),
806 dbesc($person["photo"]),
807 dbesc($person["url"]),
808 intval($contact["id"]),
814 dbesc($author.":".$guid),
815 dbesc($msg_created_at)
818 q("UPDATE `conv` SET `updated` = '%s' WHERE `id` = %d",
819 dbesc(datetime_convert()),
820 intval($conversation["id"])
824 "type" => NOTIFY_MAIL,
825 "notify_flags" => $importer["notify-flags"],
826 "language" => $importer["language"],
827 "to_name" => $importer["username"],
828 "to_email" => $importer["email"],
829 "uid" =>$importer["uid"],
830 "item" => array("subject" => $subject, "body" => $body),
831 "source_name" => $person["name"],
832 "source_link" => $person["url"],
833 "source_photo" => $person["thumb"],
834 "verb" => ACTIVITY_POST,
839 private function receive_conversation($importer, $msg, $data) {
840 $guid = notags(unxmlify($data->guid));
841 $subject = notags(unxmlify($data->subject));
842 $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
843 $author = notags(unxmlify($data->author));
844 $participants = notags(unxmlify($data->participants));
846 $messages = $data->message;
848 if (!count($messages)) {
849 logger("empty conversation");
853 $contact = self::get_allowed_contact_by_handle($importer, $msg["author"], true);
857 $conversation = null;
859 $c = q("SELECT * FROM `conv` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
860 intval($importer["uid"]),
864 $conversation = $c[0];
866 $r = q("INSERT INTO `conv` (`uid`, `guid`, `creator`, `created`, `updated`, `subject`, `recips`)
867 VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s')",
868 intval($importer["uid"]),
871 dbesc(datetime_convert("UTC", "UTC", $created_at)),
872 dbesc(datetime_convert()),
877 $c = q("SELECT * FROM `conv` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
878 intval($importer["uid"]),
883 $conversation = $c[0];
885 if (!$conversation) {
886 logger("unable to create conversation.");
890 foreach($messages as $mesg)
891 self::receive_conversation_message($importer, $contact, $data, $msg, $mesg);
896 private function construct_like_body($contact, $parent_item, $guid) {
897 $bodyverb = t('%1$s likes %2$s\'s %3$s');
899 $ulink = "[url=".$contact["url"]."]".$contact["name"]."[/url]";
900 $alink = "[url=".$parent_item["author-link"]."]".$parent_item["author-name"]."[/url]";
901 $plink = "[url=".App::get_baseurl()."/display/".urlencode($guid)."]".t("status")."[/url]";
903 return sprintf($bodyverb, $ulink, $alink, $plink);
906 private function construct_like_object($importer, $parent_item) {
907 $objtype = ACTIVITY_OBJ_NOTE;
908 $link = xmlify('<link rel="alternate" type="text/html" href="'.App::get_baseurl()."/display/".$importer["nickname"]."/".$parent_item["id"].'" />'."\n") ;
909 $parent_body = $parent_item["body"];
914 <type>$objtype</type>
916 <id>{$parent_item["uri"]}</id>
919 <content>$parent_body</content>
926 private function receive_like($importer, $sender, $data) {
927 $positive = notags(unxmlify($data->positive));
928 $guid = notags(unxmlify($data->guid));
929 $parent_type = notags(unxmlify($data->parent_type));
930 $parent_guid = notags(unxmlify($data->parent_guid));
931 $author = notags(unxmlify($data->author));
933 // likes on comments aren't supported by Diaspora - only on posts
934 // But maybe this will be supported in the future, so we will accept it.
935 if (!in_array($parent_type, array("Post", "Comment")))
938 $contact = self::get_allowed_contact_by_handle($importer, $sender, true);
942 if (self::message_exists($importer["uid"], $guid))
945 $parent_item = self::fetch_parent_item($importer["uid"], $parent_guid, $author, $contact);
949 $person = self::get_person_by_handle($author);
950 if (!is_array($person)) {
951 logger("unable to find author details");
955 // Fetch the contact id - if we know this contact
956 $author_contact = self::get_author_contact_by_url($contact, $person, $importer["uid"]);
958 // "positive" = "false" would be a Dislike - wich isn't currently supported by Diaspora
959 // We would accept this anyhow.
960 if ($positive === "true")
961 $verb = ACTIVITY_LIKE;
963 $verb = ACTIVITY_DISLIKE;
967 $datarray["uid"] = $importer["uid"];
968 $datarray["contact-id"] = $author_contact["cid"];
969 $datarray["network"] = $author_contact["network"];
971 $datarray["author-name"] = $person["name"];
972 $datarray["author-link"] = $person["url"];
973 $datarray["author-avatar"] = ((x($person,"thumb")) ? $person["thumb"] : $person["photo"]);
975 $datarray["owner-name"] = $contact["name"];
976 $datarray["owner-link"] = $contact["url"];
977 $datarray["owner-avatar"] = ((x($contact,"thumb")) ? $contact["thumb"] : $contact["photo"]);
979 $datarray["guid"] = $guid;
980 $datarray["uri"] = $author.":".$guid;
982 $datarray["type"] = "activity";
983 $datarray["verb"] = $verb;
984 $datarray["gravity"] = GRAVITY_LIKE;
985 $datarray["parent-uri"] = $parent_item["uri"];
987 $datarray["object-type"] = ACTIVITY_OBJ_NOTE;
988 $datarray["object"] = self::construct_like_object($importer, $parent_item);
990 $datarray["body"] = self::construct_like_body($contact, $parent_item, $guid);
992 $message_id = item_store($datarray);
993 // print_r($datarray);
995 // If we are the origin of the parent we store the original data and notify our followers
996 if($message_id AND $parent_item["origin"]) {
998 // Formerly we stored the signed text, the signature and the author in different fields.
999 // We now store the raw data so that we are more flexible.
1000 q("INSERT INTO `sign` (`iid`,`signed_text`) VALUES (%d,'%s')",
1001 intval($message_id),
1002 dbesc(json_encode($data))
1006 proc_run("php", "include/notifier.php", "comment-import", $message_id);
1012 private function receive_message($importer, $data) {
1013 $guid = notags(unxmlify($data->guid));
1014 $parent_guid = notags(unxmlify($data->parent_guid));
1015 $text = unxmlify($data->text);
1016 $created_at = datetime_convert("UTC", "UTC", notags(unxmlify($data->created_at)));
1017 $author = notags(unxmlify($data->author));
1018 $conversation_guid = notags(unxmlify($data->conversation_guid));
1020 $contact = self::get_allowed_contact_by_handle($importer, $author, true);
1024 $conversation = null;
1026 $c = q("SELECT * FROM `conv` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
1027 intval($importer["uid"]),
1028 dbesc($conversation_guid)
1031 $conversation = $c[0];
1033 logger("conversation not available.");
1039 $body = diaspora2bb($text);
1040 $message_uri = $author.":".$guid;
1042 $person = self::get_person_by_handle($author);
1044 logger("unable to find author details");
1048 $r = q("SELECT `id` FROM `mail` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1",
1049 dbesc($message_uri),
1050 intval($importer["uid"])
1053 logger("duplicate message already delivered.", LOGGER_DEBUG);
1057 q("INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`)
1058 VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
1059 intval($importer["uid"]),
1061 intval($conversation["id"]),
1062 dbesc($person["name"]),
1063 dbesc($person["photo"]),
1064 dbesc($person["url"]),
1065 intval($contact["id"]),
1066 dbesc($conversation["subject"]),
1070 dbesc($message_uri),
1071 dbesc($author.":".$parent_guid),
1075 q("UPDATE `conv` SET `updated` = '%s' WHERE `id` = %d",
1076 dbesc(datetime_convert()),
1077 intval($conversation["id"])
1083 private function receive_participation($importer, $data) {
1084 // I'm not sure if we can fully support this message type
1088 private function receive_photo($importer, $data) {
1089 // There doesn't seem to be a reason for this function, since the photo data is transmitted in the status message as well
1093 private function receive_poll_participation($importer, $data) {
1094 // We don't support polls by now
1098 private function receive_profile($importer, $data) {
1099 $author = notags(unxmlify($data->author));
1101 $contact = self::get_contact_by_handle($importer["uid"], $author);
1105 $name = unxmlify($data->first_name).((strlen($data->last_name)) ? " ".unxmlify($data->last_name) : "");
1106 $image_url = unxmlify($data->image_url);
1107 $birthday = unxmlify($data->birthday);
1108 $location = diaspora2bb(unxmlify($data->location));
1109 $about = diaspora2bb(unxmlify($data->bio));
1110 $gender = unxmlify($data->gender);
1111 $searchable = (unxmlify($data->searchable) == "true");
1112 $nsfw = (unxmlify($data->nsfw) == "true");
1113 $tags = unxmlify($data->tag_string);
1115 $tags = explode("#", $tags);
1117 $keywords = array();
1118 foreach ($tags as $tag) {
1119 $tag = trim(strtolower($tag));
1124 $keywords = implode(", ", $keywords);
1126 $handle_parts = explode("@", $author);
1127 $nick = $handle_parts[0];
1130 $name = $handle_parts[0];
1132 if( preg_match("|^https?://|", $image_url) === 0)
1133 $image_url = "http://".$handle_parts[1].$image_url;
1135 update_contact_avatar($image_url, $importer["uid"], $contact["id"]);
1137 // Generic birthday. We don't know the timezone. The year is irrelevant.
1139 $birthday = str_replace("1000", "1901", $birthday);
1141 if ($birthday != "")
1142 $birthday = datetime_convert("UTC", "UTC", $birthday, "Y-m-d");
1144 // this is to prevent multiple birthday notifications in a single year
1145 // if we already have a stored birthday and the 'm-d' part hasn't changed, preserve the entry, which will preserve the notify year
1147 if(substr($birthday,5) === substr($contact["bd"],5))
1148 $birthday = $contact["bd"];
1150 $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `name-date` = '%s', `bd` = '%s',
1151 `location` = '%s', `about` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `id` = %d AND `uid` = %d",
1155 dbesc(datetime_convert()),
1161 intval($contact["id"]),
1162 intval($importer["uid"])
1166 poco_check($contact["url"], $name, NETWORK_DIASPORA, $image_url, $about, $location, $gender, $keywords, "",
1167 datetime_convert(), 2, $contact["id"], $importer["uid"]);
1170 $gcontact = array("url" => $contact["url"], "network" => NETWORK_DIASPORA, "generation" => 2,
1171 "photo" => $image_url, "name" => $name, "location" => $location,
1172 "about" => $about, "birthday" => $birthday, "gender" => $gender,
1173 "addr" => $author, "nick" => $nick, "keywords" => $keywords,
1174 "hide" => !$searchable, "nsfw" => $nsfw);
1176 update_gcontact($gcontact);
1181 private function receive_request_make_friend($importer, $contact) {
1182 if($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) {
1183 q("UPDATE `contact` SET `rel` = %d, `writable` = 1 WHERE `id` = %d AND `uid` = %d",
1184 intval(CONTACT_IS_FRIEND),
1185 intval($contact["id"]),
1186 intval($importer["uid"])
1189 // send notification
1191 $r = q("SELECT `hide-friends` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
1192 intval($importer["uid"])
1195 if($r && !$r[0]["hide-friends"] && !$contact["hidden"] && intval(get_pconfig($importer["uid"], "system", "post_newfriend"))) {
1197 $self = q("SELECT * FROM `contact` WHERE `self` AND `uid` = %d LIMIT 1",
1198 intval($importer["uid"])
1201 // they are not CONTACT_IS_FOLLOWER anymore but that's what we have in the array
1203 if($self && $contact["rel"] == CONTACT_IS_FOLLOWER) {
1206 $arr["uri"] = $arr["parent-uri"] = item_new_uri(App::get_hostname(), $importer["uid"]);
1207 $arr["uid"] = $importer["uid"];
1208 $arr["contact-id"] = $self[0]["id"];
1210 $arr["type"] = 'wall';
1211 $arr["gravity"] = 0;
1213 $arr["author-name"] = $arr["owner-name"] = $self[0]["name"];
1214 $arr["author-link"] = $arr["owner-link"] = $self[0]["url"];
1215 $arr["author-avatar"] = $arr["owner-avatar"] = $self[0]["thumb"];
1216 $arr["verb"] = ACTIVITY_FRIEND;
1217 $arr["object-type"] = ACTIVITY_OBJ_PERSON;
1219 $A = "[url=".$self[0]["url"]."]".$self[0]["name"]."[/url]";
1220 $B = "[url=".$contact["url"]."]".$contact["name"]."[/url]";
1221 $BPhoto = "[url=".$contact["url"]."][img]".$contact["thumb"]."[/img][/url]";
1222 $arr["body"] = sprintf(t("%1$s is now friends with %2$s"), $A, $B)."\n\n\n".$Bphoto;
1224 $arr["object"] = "<object><type>".ACTIVITY_OBJ_PERSON."</type><title>".$contact["name"]."</title>"
1225 ."<id>".$contact["url"]."/".$contact["name"]."</id>";
1226 $arr["object"] .= "<link>".xmlify('<link rel="alternate" type="text/html" href="'.$contact["url"].'" />'."\n");
1227 $arr["object"] .= xmlify('<link rel="photo" type="image/jpeg" href="'.$contact["thumb"].'" />'."\n");
1228 $arr["object"] .= "</link></object>\n";
1229 $arr["last-child"] = 1;
1231 $arr["allow_cid"] = $user[0]["allow_cid"];
1232 $arr["allow_gid"] = $user[0]["allow_gid"];
1233 $arr["deny_cid"] = $user[0]["deny_cid"];
1234 $arr["deny_gid"] = $user[0]["deny_gid"];
1236 $i = item_store($arr);
1238 proc_run("php", "include/notifier.php", "activity", $i);
1245 private function receive_request($importer, $data) {
1246 $author = unxmlify($data->author);
1247 $recipient = unxmlify($data->recipient);
1249 if (!$author || !$recipient)
1252 $contact = self::get_contact_by_handle($importer["uid"],$author);
1256 // perhaps we were already sharing with this person. Now they're sharing with us.
1257 // That makes us friends.
1259 self::receive_request_make_friend($importer, $contact);
1263 $ret = self::get_person_by_handle($author);
1265 if (!$ret || ($ret["network"] != NETWORK_DIASPORA)) {
1266 logger("Cannot resolve diaspora handle ".$author ." for ".$recipient);
1270 $batch = (($ret["batch"]) ? $ret["batch"] : implode("/", array_slice(explode("/", $ret["url"]), 0, 3))."/receive/public");
1272 $r = q("INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`nurl`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`)
1273 VALUES (%d, '%s', '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d)",
1274 intval($importer["uid"]),
1275 dbesc($ret["network"]),
1276 dbesc($ret["addr"]),
1279 dbesc(normalise_link($ret["url"])),
1281 dbesc($ret["name"]),
1282 dbesc($ret["nick"]),
1283 dbesc($ret["photo"]),
1284 dbesc($ret["pubkey"]),
1285 dbesc($ret["notify"]),
1286 dbesc($ret["poll"]),
1291 // find the contact record we just created
1293 $contact_record = self::get_contact_by_handle($importer["uid"],$author);
1295 if (!$contact_record) {
1296 logger("unable to locate newly created contact record.");
1300 $g = q("SELECT `def_gid` FROM `user` WHERE `uid` = %d LIMIT 1",
1301 intval($importer["uid"])
1304 if($g && intval($g[0]["def_gid"]))
1305 group_add_member($importer["uid"], "", $contact_record["id"], $g[0]["def_gid"]);
1307 if($importer["page-flags"] == PAGE_NORMAL) {
1309 $hash = random_string().(string)time(); // Generate a confirm_key
1311 $ret = q("INSERT INTO `intro` (`uid`, `contact-id`, `blocked`, `knowyou`, `note`, `hash`, `datetime`)
1312 VALUES (%d, %d, %d, %d, '%s', '%s', '%s')",
1313 intval($importer["uid"]),
1314 intval($contact_record["id"]),
1317 dbesc(t("Sharing notification from Diaspora network")),
1319 dbesc(datetime_convert())
1323 // automatic friend approval
1325 update_contact_avatar($contact_record["photo"],$importer["uid"],$contact_record["id"]);
1327 // technically they are sharing with us (CONTACT_IS_SHARING),
1328 // but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX
1329 // we are going to change the relationship and make them a follower.
1331 if($importer["page-flags"] == PAGE_FREELOVE)
1332 $new_relation = CONTACT_IS_FRIEND;
1334 $new_relation = CONTACT_IS_FOLLOWER;
1336 $r = q("UPDATE `contact` SET `rel` = %d,
1344 intval($new_relation),
1345 dbesc(datetime_convert()),
1346 dbesc(datetime_convert()),
1347 intval($contact_record["id"])
1350 $u = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($importer["uid"]));
1352 $ret = diaspora_share($u[0], $contact_record);
1358 private function get_original_item($guid, $orig_author, $author) {
1360 // Do we already have this item?
1361 $r = q("SELECT `body`, `tag`, `app`, `created`, `object-type`, `uri`, `guid`,
1362 `author-name`, `author-link`, `author-avatar`
1363 FROM `item` WHERE `guid` = '%s' AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1",
1367 logger("reshared message ".$guid." already exists on system.");
1369 // Maybe it is already a reshared item?
1370 // Then refetch the content, since there can be many side effects with reshared posts from other networks or reshares from reshares
1371 if (api_share_as_retweet($r[0]))
1378 $server = "https://".substr($orig_author, strpos($orig_author, "@") + 1);
1379 logger("1st try: reshared message ".$guid." will be fetched from original server: ".$server);
1380 $item_id = self::store_by_guid($guid, $server);
1383 $server = "https://".substr($author, strpos($author, "@") + 1);
1384 logger("2nd try: reshared message ".$guid." will be fetched from sharer's server: ".$server);
1385 $item = self::store_by_guid($guid, $server);
1388 $server = "http://".substr($orig_author, strpos($orig_author, "@") + 1);
1389 logger("3rd try: reshared message ".$guid." will be fetched from original server: ".$server);
1390 $item = self::store_by_guid($guid, $server);
1393 $server = "http://".substr($author, strpos($author, "@") + 1);
1394 logger("4th try: reshared message ".$guid." will be fetched from sharer's server: ".$server);
1395 $item = self::store_by_guid($guid, $server);
1399 $r = q("SELECT `body`, `tag`, `app`, `created`, `object-type`, `uri`, `guid`,
1400 `author-name`, `author-link`, `author-avatar`
1401 FROM `item` WHERE `id` = %d AND `visible` AND NOT `deleted` AND `body` != '' LIMIT 1",
1412 private function receive_reshare($importer, $data) {
1413 $root_author = notags(unxmlify($data->root_author));
1414 $root_guid = notags(unxmlify($data->root_guid));
1415 $guid = notags(unxmlify($data->guid));
1416 $author = notags(unxmlify($data->author));
1417 $public = notags(unxmlify($data->public));
1418 $created_at = notags(unxmlify($data->created_at));
1420 $contact = self::get_allowed_contact_by_handle($importer, $author, false);
1424 if (self::message_exists($importer["uid"], $guid))
1427 $original_item = self::get_original_item($root_guid, $root_author, $author);
1428 if (!$original_item)
1431 $datarray = array();
1433 $datarray["uid"] = $importer["uid"];
1434 $datarray["contact-id"] = $contact["id"];
1435 $datarray["network"] = NETWORK_DIASPORA;
1437 $datarray["author-name"] = $contact["name"];
1438 $datarray["author-link"] = $contact["url"];
1439 $datarray["author-avatar"] = ((x($contact,"thumb")) ? $contact["thumb"] : $contact["photo"]);
1441 $datarray["owner-name"] = $datarray["author-name"];
1442 $datarray["owner-link"] = $datarray["author-link"];
1443 $datarray["owner-avatar"] = $datarray["author-avatar"];
1445 $datarray["guid"] = $guid;
1446 $datarray["uri"] = $datarray["parent-uri"] = $author.":".$guid;
1448 $datarray["verb"] = ACTIVITY_POST;
1449 $datarray["gravity"] = GRAVITY_PARENT;
1451 $datarray["object"] = json_encode($data);
1453 $prefix = share_header($original_item["author-name"], $original_item["author-link"], $original_item["author-avatar"],
1454 $original_item["guid"], $original_item["created"], $original_item["uri"]);
1455 $datarray["body"] = $prefix.$original_item["body"]."[/share]";
1457 $datarray["tag"] = $original_item["tag"];
1458 $datarray["app"] = $original_item["app"];
1460 $datarray["plink"] = self::plink($author, $guid);
1461 $datarray["private"] = (($public == "false") ? 1 : 0);
1462 $datarray["changed"] = $datarray["created"] = $datarray["edited"] = datetime_convert("UTC", "UTC", $created_at);
1464 $datarray["object-type"] = $original_item["object-type"];
1466 self::fetch_guid($datarray);
1467 $message_id = item_store($datarray);
1468 // print_r($datarray);
1473 private function item_retraction($importer, $contact, $data) {
1474 $target_type = notags(unxmlify($data->target_type));
1475 $target_guid = notags(unxmlify($data->target_guid));
1476 $author = notags(unxmlify($data->author));
1478 $person = self::get_person_by_handle($author);
1479 if (!is_array($person)) {
1480 logger("unable to find author detail for ".$author);
1484 $r = q("SELECT `id`, `parent`, `parent-uri`, `author-link` FROM `item` WHERE `guid` = '%s' AND `uid` = %d AND NOT `file` LIKE '%%[%%' LIMIT 1",
1485 dbesc($target_guid),
1486 intval($importer["uid"])
1491 // Only delete it if the author really fits
1492 if (!link_compare($r[0]["author-link"],$person["url"]))
1495 // Check if the sender is the thread owner
1496 $p = q("SELECT `author-link`, `origin` FROM `item` WHERE `id` = %d",
1497 intval($r[0]["parent"]));
1499 // Only delete it if the parent author really fits
1500 if (!link_compare($p[0]["author-link"], $contact["url"]))
1503 // Currently we don't have a central deletion function that we could use in this case. The function "item_drop" doesn't work for that case
1504 q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = '' , `title` = '' WHERE `id` = %d",
1505 dbesc(datetime_convert()),
1506 dbesc(datetime_convert()),
1509 delete_thread($r[0]["id"], $r[0]["parent-uri"]);
1511 // Now check if the retraction needs to be relayed by us
1512 if($p[0]["origin"]) {
1514 // Formerly we stored the signed text, the signature and the author in different fields.
1515 // We now store the raw data so that we are more flexible.
1516 q("INSERT INTO `sign` (`iid`,`signed_text`) VALUES (%d,'%s')",
1517 intval($r[0]["id"]),
1518 dbesc(json_encode($data))
1522 proc_run("php", "include/notifier.php", "drop", $r[0]["id"]);
1526 private function receive_retraction($importer, $sender, $data) {
1527 $target_type = notags(unxmlify($data->target_type));
1529 $contact = self::get_contact_by_handle($importer["uid"], $sender);
1531 logger("cannot find contact for sender: ".$sender." and user ".$importer["uid"]);
1535 switch ($target_type) {
1538 case "Post": // "Post" will be supported in a future version
1540 case "StatusMessage":
1541 return self::item_retraction($importer, $contact, $data);;
1544 contact_remove($contact["id"]);
1548 logger("Unknown target type ".$target_type);
1554 private function receive_status_message($importer, $data) {
1556 $raw_message = unxmlify($data->raw_message);
1557 $guid = notags(unxmlify($data->guid));
1558 $author = notags(unxmlify($data->author));
1559 $public = notags(unxmlify($data->public));
1560 $created_at = notags(unxmlify($data->created_at));
1561 $provider_display_name = notags(unxmlify($data->provider_display_name));
1563 /// @todo enable support for polls
1564 //if ($data->poll) {
1565 // foreach ($data->poll AS $poll)
1569 $contact = self::get_allowed_contact_by_handle($importer, $author, false);
1573 if (self::message_exists($importer["uid"], $guid))
1577 if ($data->location)
1578 foreach ($data->location->children() AS $fieldname => $data)
1579 $address[$fieldname] = notags(unxmlify($data));
1581 $body = diaspora2bb($raw_message);
1583 $datarray = array();
1586 foreach ($data->photo AS $photo)
1587 $body = "[img]".$photo->remote_photo_path.$photo->remote_photo_name."[/img]\n".$body;
1589 $datarray["object-type"] = ACTIVITY_OBJ_PHOTO;
1591 $datarray["object-type"] = ACTIVITY_OBJ_NOTE;
1593 // Add OEmbed and other information to the body
1594 if (!self::is_redmatrix($contact["url"]))
1595 $body = add_page_info_to_body($body, false, true);
1598 $datarray["uid"] = $importer["uid"];
1599 $datarray["contact-id"] = $contact["id"];
1600 $datarray["network"] = NETWORK_DIASPORA;
1602 $datarray["author-name"] = $contact["name"];
1603 $datarray["author-link"] = $contact["url"];
1604 $datarray["author-avatar"] = ((x($contact,"thumb")) ? $contact["thumb"] : $contact["photo"]);
1606 $datarray["owner-name"] = $datarray["author-name"];
1607 $datarray["owner-link"] = $datarray["author-link"];
1608 $datarray["owner-avatar"] = $datarray["author-avatar"];
1610 $datarray["guid"] = $guid;
1611 $datarray["uri"] = $datarray["parent-uri"] = $author.":".$guid;
1613 $datarray["verb"] = ACTIVITY_POST;
1614 $datarray["gravity"] = GRAVITY_PARENT;
1616 $datarray["object"] = json_encode($data);
1618 $datarray["body"] = $body;
1620 if ($provider_display_name != "")
1621 $datarray["app"] = $provider_display_name;
1623 $datarray["plink"] = self::plink($author, $guid);
1624 $datarray["private"] = (($public == "false") ? 1 : 0);
1625 $datarray["changed"] = $datarray["created"] = $datarray["edited"] = datetime_convert("UTC", "UTC", $created_at);
1627 if (isset($address["address"]))
1628 $datarray["location"] = $address["address"];
1630 if (isset($address["lat"]) AND isset($address["lng"]))
1631 $datarray["coord"] = $address["lat"]." ".$address["lng"];
1633 self::fetch_guid($datarray);
1634 $message_id = item_store($datarray);
1635 // print_r($datarray);
1637 logger("Stored item with message id ".$message_id, LOGGER_DEBUG);