<?php
/**
- * @file include/diaspora.php
+ * @file src/Protocol/diaspora.php
* @brief The implementation of the diaspora protocol
*
* The new protocol is described here: http://diaspora.github.io/diaspora_federation/index.html
use Friendica\Core\PConfig;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
-use Friendica\Model\GlobalContact;
+use Friendica\Model\Contact;
+use Friendica\Model\GContact;
+use Friendica\Model\Group;
+use Friendica\Model\Profile;
+use Friendica\Model\User;
use Friendica\Network\Probe;
-use Friendica\Object\Contact;
-use Friendica\Object\Profile;
use Friendica\Util\XML;
use dba;
use SimpleXMLElement;
+require_once 'include/dba.php';
require_once 'include/items.php';
require_once 'include/bb2diaspora.php';
-require_once 'include/Photo.php';
-require_once 'include/group.php';
require_once 'include/datetime.php';
require_once 'include/queue_fn.php';
*/
class Diaspora
{
-
/**
* @brief Return a list of relay servers
*
} elseif (!in_array($fieldname, array("author_signature", "parent_author_signature", "target_author_signature"))) {
if ($signed_data != "") {
$signed_data .= ";";
- $signed_data_parent .= ";";
}
$signed_data .= $entry;
/**
* @brief Get a contact id for a given handle
*
+ * @todo Move to Friendica\Model\Contact
+ *
* @param int $uid The user id
* @param string $handle The handle in the format user@domain.tld
*
- * @return The contact id
+ * @return int Contact id
*/
private static function contactByHandle($uid, $handle)
{
* That makes us friends.
* Normally this should have handled by getting a request - but this could get lost
*/
- if ($contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) {
- dba::update(
- 'contact',
- array('rel' => CONTACT_IS_FRIEND, 'writable' => true),
- array('id' => $contact["id"], 'uid' => $contact["uid"])
- );
-
- $contact["rel"] = CONTACT_IS_FRIEND;
- logger("defining user ".$contact["nick"]." as friend");
- }
+ // It is deactivated by now, due to side effects. See issue https://github.com/friendica/friendica/pull/4033
+ // It is not removed by now. Possibly the code is needed?
+ //if (!$is_comment && $contact["rel"] == CONTACT_IS_FOLLOWER && in_array($importer["page-flags"], array(PAGE_FREELOVE))) {
+ // dba::update(
+ // 'contact',
+ // array('rel' => CONTACT_IS_FRIEND, 'writable' => true),
+ // array('id' => $contact["id"], 'uid' => $contact["uid"])
+ // );
+ //
+ // $contact["rel"] = CONTACT_IS_FRIEND;
+ // logger("defining user ".$contact["nick"]." as friend");
+ //}
// We don't seem to like that person
if ($contact["blocked"] || $contact["readonly"] || $contact["archive"]) {
preg_replace_callback(
$expression,
function ($match) use ($item) {
- return self::fetchGuidSub($match, $item);
+ self::fetchGuidSub($match, $item);
},
$item["body"]
);
preg_replace_callback(
"&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi",
function ($match) use ($item) {
- return self::fetchGuidSub($match, $item);
+ self::fetchGuidSub($match, $item);
},
$item["body"]
);
* @param string $body The item body to replace links from
* @param string $author_link The author link for missing local contact fallback
*
- * @return the replaced string
+ * @return string the replaced string
*/
public static function replacePeopleGuid($body, $author_link)
{
if ($r) {
$cid = $r[0]["id"];
$network = $r[0]["network"];
-
- // We are receiving content from a user that possibly is about to be terminated
- // This means the user is vital, so we remove a possible termination date.
- Contact::unmarkForArchival($r[0]);
} else {
$cid = $contact["id"];
$network = NETWORK_DIASPORA;
$image_url = "http://".$handle_parts[1].$image_url;
}
- update_contact_avatar($image_url, $importer["uid"], $contact["id"]);
+ Contact::updateAvatar($image_url, $importer["uid"], $contact["id"]);
// Generic birthday. We don't know the timezone. The year is irrelevant.
"addr" => $author, "nick" => $nick, "keywords" => $keywords,
"hide" => !$searchable, "nsfw" => $nsfw);
- $gcid = GlobalContact::update($gcontact);
+ $gcid = GContact::update($gcontact);
- GlobalContact::link($gcid, $importer["uid"], $contact["id"]);
+ GContact::link($gcid, $importer["uid"], $contact["id"]);
logger("Profile of contact ".$contact["id"]." stored for user ".$importer["uid"], LOGGER_DEBUG);
$A = "[url=".$self[0]["url"]."]".$self[0]["name"]."[/url]";
$B = "[url=".$contact["url"]."]".$contact["name"]."[/url]";
$BPhoto = "[url=".$contact["url"]."][img]".$contact["thumb"]."[/img][/url]";
- $arr["body"] = sprintf(t("%1$s is now friends with %2$s"), $A, $B)."\n\n\n".$Bphoto;
+ $arr["body"] = sprintf(t('%1$s is now friends with %2$s'), $A, $B)."\n\n\n".$BPhoto;
$arr["object"] = self::constructNewFriendObject($contact);
$arr["last-child"] = 1;
- $arr["allow_cid"] = $user[0]["allow_cid"];
- $arr["allow_gid"] = $user[0]["allow_gid"];
- $arr["deny_cid"] = $user[0]["deny_cid"];
- $arr["deny_gid"] = $user[0]["deny_gid"];
+ $user = dba::select('user', ['allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'], ['uid' => $importer["uid"]], ['limit' => 1]);
+
+ $arr["allow_cid"] = $user["allow_cid"];
+ $arr["allow_gid"] = $user["allow_gid"];
+ $arr["deny_cid"] = $user["deny_cid"];
+ $arr["deny_gid"] = $user["deny_gid"];
$i = item_store($arr);
if ($i) {
logger("Author ".$author." was added as contact number ".$contact_record["id"].".", LOGGER_DEBUG);
- $def_gid = get_default_group($importer['uid'], $ret["network"]);
-
- if (intval($def_gid)) {
- group_add_member($importer["uid"], "", $contact_record["id"], $def_gid);
- }
+ Group::addMember(User::getDefaultGroup($importer['uid'], $ret["network"]), $contact_record['id']);
- update_contact_avatar($ret["photo"], $importer['uid'], $contact_record["id"], true);
+ Contact::updateAvatar($ret["photo"], $importer['uid'], $contact_record["id"], true);
if ($importer["page-flags"] == PAGE_NORMAL) {
logger("Sending intra message for author ".$author.".", LOGGER_DEBUG);
logger("Does an automatic friend approval for author ".$author.".", LOGGER_DEBUG);
- update_contact_avatar($contact_record["photo"], $importer["uid"], $contact_record["id"]);
+ Contact::updateAvatar($contact_record["photo"], $importer["uid"], $contact_record["id"]);
// technically they are sharing with us (CONTACT_IS_SHARING),
// but if our page-type is PAGE_COMMUNITY or PAGE_SOAPBOX
$return_code = self::transmit($owner, $contact, $envelope, $public_batch, false, $guid);
}
- logger("guid: ".$item["guid"]." result ".$return_code, LOGGER_DEBUG);
+ logger("guid: ".$guid." result ".$return_code, LOGGER_DEBUG);
return $return_code;
}
foreach ($recips as $recip) {
logger("Send updated profile data for user ".$uid." to contact ".$recip["id"], LOGGER_DEBUG);
+ /// @fixme $profile isn't available here
self::buildAndTransmit($profile, $recip, "profile", $message, false, "", true);
}
}