use Friendica\Core\PConfig;
use Friendica\Core\System;
use Friendica\Core\Worker;
-use Friendica\Database\DBM;
+use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Network\Probe;
use Friendica\Util\Crypto;
use Friendica\Util\DateTimeFormat;
+use Friendica\Util\Map;
use Friendica\Util\Network;
use Friendica\Util\XML;
-use Friendica\Util\Map;
-use dba;
use SimpleXMLElement;
require_once 'include/dba.php';
*
* @return array of relay servers
*/
- public static function relayList($item_id, $contacts = [])
+ public static function relayList($item_id, array $contacts = [])
{
$serverlist = [];
// Fetching relay servers
$serverdata = Config::get("system", "relay_server");
- if ($serverdata != "") {
+
+ if (!empty($serverdata)) {
$servers = explode(",", $serverdata);
foreach ($servers as $server) {
$serverlist[$server] = trim($server);
if (Config::get("system", "relay_directly", false)) {
// We distribute our stuff based on the parent to ensure that the thread will be complete
$parent = Item::selectFirst(['parent'], ['id' => $item_id]);
- if (!DBM::is_result($parent)) {
+ if (!DBA::isResult($parent)) {
return;
}
// Servers that want to get all content
- $servers = dba::select('gserver', ['url'], ['relay-subscribe' => true, 'relay-scope' => 'all']);
- while ($server = dba::fetch($servers)) {
+ $servers = DBA::select('gserver', ['url'], ['relay-subscribe' => true, 'relay-scope' => 'all']);
+ while ($server = DBA::fetch($servers)) {
$serverlist[$server['url']] = $server['url'];
}
// All tags of the current post
$condition = ['otype' => TERM_OBJ_POST, 'type' => TERM_HASHTAG, 'oid' => $parent['parent']];
- $tags = dba::select('term', ['term'], $condition);
+ $tags = DBA::select('term', ['term'], $condition);
$taglist = [];
- while ($tag = dba::fetch($tags)) {
+ while ($tag = DBA::fetch($tags)) {
$taglist[] = $tag['term'];
}
// All servers who wants content with this tag
$tagserverlist = [];
if (!empty($taglist)) {
- $tagserver = dba::select('gserver-tag', ['gserver-id'], ['tag' => $taglist]);
- while ($server = dba::fetch($tagserver)) {
+ $tagserver = DBA::select('gserver-tag', ['gserver-id'], ['tag' => $taglist]);
+ while ($server = DBA::fetch($tagserver)) {
$tagserverlist[] = $server['gserver-id'];
}
}
// All adresses with the given id
if (!empty($tagserverlist)) {
- $servers = dba::select('gserver', ['url'], ['relay-subscribe' => true, 'relay-scope' => 'tags', 'id' => $tagserverlist]);
- while ($server = dba::fetch($servers)) {
+ $servers = DBA::select('gserver', ['url'], ['relay-subscribe' => true, 'relay-scope' => 'tags', 'id' => $tagserverlist]);
+ while ($server = DBA::fetch($servers)) {
$serverlist[$server['url']] = $server['url'];
}
}
// Fetch the relay contact
$condition = ['uid' => 0, 'nurl' => normalise_link($server_url),
'contact-type' => ACCOUNT_TYPE_RELAY];
- $contact = dba::selectFirst('contact', $fields, $condition);
+ $contact = DBA::selectFirst('contact', $fields, $condition);
- if (DBM::is_result($contact)) {
+ if (DBA::isResult($contact)) {
if ($contact['archive'] || $contact['blocked']) {
return false;
}
} else {
self::setRelayContact($server_url);
- $contact = dba::selectFirst('contact', $fields, $condition);
- if (DBM::is_result($contact)) {
+ $contact = DBA::selectFirst('contact', $fields, $condition);
+ if (DBA::isResult($contact)) {
return $contact;
}
}
* @param string $server_url The url of the server
* @param array $network_fields Optional network specific fields
*/
- public static function setRelayContact($server_url, $network_fields = [])
+ public static function setRelayContact($server_url, array $network_fields = [])
{
$fields = ['created' => DateTimeFormat::utcNow(),
'name' => 'relay', 'nick' => 'relay',
$condition = ['uid' => 0, 'nurl' => normalise_link($server_url),
'contact-type' => ACCOUNT_TYPE_RELAY];
- if (dba::exists('contact', $condition)) {
+ if (DBA::exists('contact', $condition)) {
unset($fields['created']);
}
- dba::update('contact', $fields, $condition, true);
+ DBA::update('contact', $fields, $condition, true);
}
/**
*
* @return array of relay servers
*/
- public static function participantsForThread($thread, $contacts)
+ public static function participantsForThread($thread, array $contacts)
{
- $r = dba::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`name`, `contact`.`network`,
+ $r = DBA::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`name`, `contact`.`network`,
`fcontact`.`batch` AS `fbatch`, `fcontact`.`network` AS `fnetwork` FROM `participation`
INNER JOIN `contact` ON `contact`.`id` = `participation`.`cid`
INNER JOIN `fcontact` ON `fcontact`.`id` = `participation`.`fid`
WHERE `participation`.`iid` = ?", $thread);
- while ($contact = dba::fetch($r)) {
+ while ($contact = DBA::fetch($r)) {
if (!empty($contact['fnetwork'])) {
$contact['network'] = $contact['fnetwork'];
}
$contacts[] = $contact;
}
}
- dba::close($r);
+ DBA::close($r);
return $contacts;
}
* 'author' -> author diaspora handle
* 'key' -> author public key (converted to pkcs#8)
*/
- public static function decodeRaw($importer, $raw)
+ public static function decodeRaw(array $importer, $raw)
{
$data = json_decode($raw);
* 'author' -> author diaspora handle
* 'key' -> author public key (converted to pkcs#8)
*/
- public static function decode($importer, $xml)
+ public static function decode(array $importer, $xml)
{
$public = false;
$basedom = XML::parseString($xml);
*
* @return int The message id of the generated message, "true" or "false" if there was an error
*/
- public static function dispatch($importer, $msg, $fields = null)
+ public static function dispatch(array $importer, $msg, $fields = null)
{
// The sender is the handle of the contact that sent the message.
// This will often be different with relayed messages (for example "like" and "comment")
{
$update = false;
- $person = dba::selectFirst('fcontact', [], ['network' => NETWORK_DIASPORA, 'addr' => $handle]);
- if (DBM::is_result($person)) {
+ $person = DBA::selectFirst('fcontact', [], ['network' => NETWORK_DIASPORA, 'addr' => $handle]);
+ if (DBA::isResult($person)) {
logger("In cache " . print_r($person, true), LOGGER_DEBUG);
// update record occasionally so it doesn't get stale
}
}
- if (!DBM::is_result($person) || $update) {
+ if (!DBA::isResult($person) || $update) {
logger("create or refresh", LOGGER_DEBUG);
$r = Probe::uri($handle, NETWORK_DIASPORA);
self::updateFContact($r);
// Fetch the updated or added contact
- $person = dba::selectFirst('fcontact', [], ['network' => NETWORK_DIASPORA, 'addr' => $handle]);
- if (!DBM::is_result($person)) {
+ $person = DBA::selectFirst('fcontact', [], ['network' => NETWORK_DIASPORA, 'addr' => $handle]);
+ if (!DBA::isResult($person)) {
$person = $r;
}
}
$condition = ['url' => $arr["url"], 'network' => $arr["network"]];
- dba::update('fcontact', $fields, $condition, true);
+ DBA::update('fcontact', $fields, $condition, true);
}
/**
intval($pcontact_id)
);
- if (DBM::is_result($r)) {
+ if (DBA::isResult($r)) {
return strtolower($r[0]["addr"]);
}
}
intval($contact_id)
);
- if (DBM::is_result($r)) {
+ if (DBA::isResult($r)) {
$contact = $r[0];
logger("contact 'self' = ".$contact['self']." 'url' = ".$contact['url'], LOGGER_DEBUG);
$r = q(
"SELECT `url` FROM `fcontact` WHERE `url` != '' AND `network` = '%s' AND `guid` = '%s'",
- dbesc(NETWORK_DIASPORA),
- dbesc($fcontact_guid)
+ DBA::escape(NETWORK_DIASPORA),
+ DBA::escape($fcontact_guid)
);
- if (DBM::is_result($r)) {
+ if (DBA::isResult($r)) {
return $r[0]['url'];
}
*/
private static function contactByHandle($uid, $handle)
{
- // First do a direct search on the contact table
- $r = q(
- "SELECT * FROM `contact` WHERE `uid` = %d AND `addr` = '%s' LIMIT 1",
- intval($uid),
- dbesc($handle)
- );
+ $cid = Contact::getIdForURL($handle, $uid);
+ if (!$cid) {
+ $handle_parts = explode("@", $handle);
+ $nurl_sql = "%%://" . $handle_parts[1] . "%%/profile/" . $handle_parts[0];
+ $cid = Contact::getIdForURL($nurl_sql, $uid);
+ }
- if (DBM::is_result($r)) {
- return $r[0];
- } else {
- /*
- * We haven't found it?
- * We use another function for it that will possibly create a contact entry.
- */
- $cid = Contact::getIdForURL($handle, $uid);
-
- if ($cid > 0) {
- /// @TODO Contact retrieval should be encapsulated into an "entity" class like `Contact`
- $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
-
- if (DBM::is_result($r)) {
- return $r[0];
- }
- }
+ if (!$cid) {
+ logger("Haven't found a contact for user " . $uid . " and handle " . $handle, LOGGER_DEBUG);
+ return false;
}
- $handle_parts = explode("@", $handle);
- $nurl_sql = "%%://".$handle_parts[1]."%%/profile/".$handle_parts[0];
- $r = q(
- "SELECT * FROM `contact` WHERE `network` = '%s' AND `uid` = %d AND `nurl` LIKE '%s' LIMIT 1",
- dbesc(NETWORK_DFRN),
- intval($uid),
- dbesc($nurl_sql)
- );
- if (DBM::is_result($r)) {
- return $r[0];
+ $contact = dba::selectFirst('contact', [], ['id' => $cid]);
+ if (!DBA::isResult($contact)) {
+ // This here shouldn't happen at all
+ logger("Haven't found a contact for user " . $uid . " and handle " . $handle, LOGGER_DEBUG);
+ return false;
}
- logger("Haven't found contact for user ".$uid." and handle ".$handle, LOGGER_DEBUG);
- return false;
+ return $contact;
}
/**
*
* @return bool is the contact allowed to post?
*/
- private static function postAllow($importer, $contact, $is_comment = false)
+ private static function postAllow(array $importer, array $contact, $is_comment = false)
{
/*
* Perhaps we were already sharing with this person. Now they're sharing with us.
*
* @return array The contact data
*/
- private static function allowedContactByHandle($importer, $handle, $is_comment = false)
+ private static function allowedContactByHandle(array $importer, $handle, $is_comment = false)
{
$contact = self::contactByHandle($importer["uid"], $handle);
if (!$contact) {
logger("A Contact for handle ".$handle." and user ".$importer["uid"]." was not found");
// If a contact isn't found, we accept it anyway if it is a comment
- if ($is_comment) {
+ if ($is_comment && ($importer["uid"] != 0)) {
+ return self::contactByHandle(0, $handle);
+ } elseif ($is_comment) {
return $importer;
} else {
return false;
private static function messageExists($uid, $guid)
{
$item = Item::selectFirst(['id'], ['uid' => $uid, 'guid' => $guid]);
- if (DBM::is_result($item)) {
+ if (DBA::isResult($item)) {
logger("message ".$guid." already exists for user ".$uid);
return $item["id"];
}
* @param array $item The item array
* @return void
*/
- private static function fetchGuid($item)
+ private static function fetchGuid(array $item)
{
$expression = "=diaspora://.*?/post/([0-9A-Za-z\-_@.:]{15,254}[0-9A-Za-z])=ism";
preg_replace_callback(
private static function storeByGuid($guid, $server, $uid = 0)
{
$serverparts = parse_url($server);
+
+ if (empty($serverparts["host"]) || empty($serverparts["scheme"])) {
+ return false;
+ }
+
$server = $serverparts["scheme"]."://".$serverparts["host"];
logger("Trying to fetch item ".$guid." from ".$server, LOGGER_DEBUG);
$author = "";
// Fetch the author - for the old and the new Diaspora version
- if ($source_xml->post->status_message->diaspora_handle) {
+ if ($source_xml->post->status_message && $source_xml->post->status_message->diaspora_handle) {
$author = (string)$source_xml->post->status_message->diaspora_handle;
} elseif ($source_xml->author && ($source_xml->getName() == "status_message")) {
$author = (string)$source_xml->author;
*
* @return array the item record
*/
- private static function parentItem($uid, $guid, $author, $contact)
+ private static function parentItem($uid, $guid, $author, array $contact)
{
$fields = ['id', 'parent', 'body', 'wall', 'uri', 'guid', 'private', 'origin',
'author-name', 'author-link', 'author-avatar',
$condition = ['uid' => $uid, 'guid' => $guid];
$item = Item::selectFirst($fields, $condition);
- if (!DBM::is_result($item)) {
+ if (!DBA::isResult($item)) {
$result = self::storeByGuid($guid, $contact["url"], $uid);
if (!$result) {
}
}
- if (!DBM::is_result($item)) {
+ if (!DBA::isResult($item)) {
logger("parent item not found: parent: ".$guid." - user: ".$uid);
return false;
} else {
private static function authorContactByUrl($def_contact, $person, $uid)
{
$condition = ['nurl' => normalise_link($person["url"]), 'uid' => $uid];
- $contact = dba::selectFirst('contact', ['id', 'network'], $condition);
- if (DBM::is_result($contact)) {
+ $contact = DBA::selectFirst('contact', ['id', 'network'], $condition);
+ if (DBA::isResult($contact)) {
$cid = $contact["id"];
$network = $contact["network"];
} else {
*
* @return bool Success
*/
- private static function receiveAccountMigration($importer, $data)
+ private static function receiveAccountMigration(array $importer, $data)
{
$old_handle = notags(unxmlify($data->author));
$new_handle = notags(unxmlify($data->profile->author));
'notify' => $data['notify'], 'poll' => $data['poll'],
'network' => $data['network']];
- dba::update('contact', $fields, ['addr' => $old_handle]);
+ DBA::update('contact', $fields, ['addr' => $old_handle]);
$fields = ['url' => $data['url'], 'nurl' => normalise_link($data['url']),
'name' => $data['name'], 'nick' => $data['nick'],
'notify' => $data['notify'], 'photo' => $data['photo'],
'server_url' => $data['baseurl'], 'network' => $data['network']];
- dba::update('gcontact', $fields, ['addr' => $old_handle]);
+ DBA::update('gcontact', $fields, ['addr' => $old_handle]);
logger('Contacts are updated.');
{
$author = notags(unxmlify($data->author));
- $contacts = dba::select('contact', ['id'], ['addr' => $author]);
- while ($contact = dba::fetch($contacts)) {
+ $contacts = DBA::select('contact', ['id'], ['addr' => $author]);
+ while ($contact = DBA::fetch($contacts)) {
Contact::remove($contact["id"]);
}
- dba::delete('gcontact', ['addr' => $author]);
+ DBA::delete('gcontact', ['addr' => $author]);
logger('Removed contacts for ' . $author);
private static function getUriFromGuid($author, $guid, $onlyfound = false)
{
$item = Item::selectFirst(['uri'], ['guid' => $guid]);
- if (DBM::is_result($item)) {
+ if (DBA::isResult($item)) {
return $item["uri"];
} elseif (!$onlyfound) {
$contact = Contact::getDetailsByAddr($author, 0);
private static function getGuidFromUri($uri, $uid)
{
$item = Item::selectFirst(['guid'], ['uri' => $uri, 'uid' => $uid]);
- if (DBM::is_result($item)) {
+ if (DBA::isResult($item)) {
return $item["guid"];
} else {
return false;
private static function importerForGuid($guid)
{
$item = Item::selectFirst(['uid'], ['origin' => true, 'guid' => $guid]);
- if (DBM::is_result($item)) {
+ if (DBA::isResult($item)) {
logger("Found user ".$item['uid']." as owner of item ".$guid, LOGGER_DEBUG);
- $contact = dba::selectFirst('contact', [], ['self' => true, 'uid' => $item['uid']]);
- if (DBM::is_result($contact)) {
+ $contact = DBA::selectFirst('contact', [], ['self' => true, 'uid' => $item['uid']]);
+ if (DBA::isResult($contact)) {
return $contact;
}
}
*
* @return int The message id of the generated comment or "false" if there was an error
*/
- private static function receiveComment($importer, $sender, $data, $xml)
+ private static function receiveComment(array $importer, $sender, $data, $xml)
{
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
$datarray["guid"] = $guid;
$datarray["uri"] = self::getUriFromGuid($author, $guid);
- $datarray["type"] = "remote-comment";
$datarray["verb"] = ACTIVITY_POST;
$datarray["gravity"] = GRAVITY_COMMENT;
*
* @return bool "true" if it was successful
*/
- private static function receiveConversationMessage($importer, $contact, $data, $msg, $mesg, $conversation)
+ private static function receiveConversationMessage(array $importer, array $contact, $data, $msg, $mesg, $conversation)
{
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
$person = self::personByHandle($msg_author);
- dba::lock('mail');
+ DBA::lock('mail');
$r = q(
"SELECT `id` FROM `mail` WHERE `guid` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($msg_guid),
+ DBA::escape($msg_guid),
intval($importer["uid"])
);
- if (DBM::is_result($r)) {
+ if (DBA::isResult($r)) {
logger("duplicate message already delivered.", LOGGER_DEBUG);
return false;
}
"INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`)
VALUES (%d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
intval($importer["uid"]),
- dbesc($msg_guid),
+ DBA::escape($msg_guid),
intval($conversation["id"]),
- dbesc($person["name"]),
- dbesc($person["photo"]),
- dbesc($person["url"]),
+ DBA::escape($person["name"]),
+ DBA::escape($person["photo"]),
+ DBA::escape($person["url"]),
intval($contact["id"]),
- dbesc($subject),
- dbesc($body),
+ DBA::escape($subject),
+ DBA::escape($body),
0,
0,
- dbesc($message_uri),
- dbesc($author.":".$guid),
- dbesc($msg_created_at)
+ DBA::escape($message_uri),
+ DBA::escape($author.":".$guid),
+ DBA::escape($msg_created_at)
);
- dba::unlock();
+ DBA::unlock();
- dba::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $conversation["id"]]);
+ DBA::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $conversation["id"]]);
notification(
[
*
* @return bool Success
*/
- private static function receiveConversation($importer, $msg, $data)
+ private static function receiveConversation(array $importer, $msg, $data)
{
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
$c = q(
"SELECT * FROM `conv` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
intval($importer["uid"]),
- dbesc($guid)
+ DBA::escape($guid)
);
if ($c)
$conversation = $c[0];
"INSERT INTO `conv` (`uid`, `guid`, `creator`, `created`, `updated`, `subject`, `recips`)
VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s')",
intval($importer["uid"]),
- dbesc($guid),
- dbesc($author),
- dbesc($created_at),
- dbesc(DateTimeFormat::utcNow()),
- dbesc($subject),
- dbesc($participants)
+ DBA::escape($guid),
+ DBA::escape($author),
+ DBA::escape($created_at),
+ DBA::escape(DateTimeFormat::utcNow()),
+ DBA::escape($subject),
+ DBA::escape($participants)
);
if ($r) {
$c = q(
"SELECT * FROM `conv` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
intval($importer["uid"]),
- dbesc($guid)
+ DBA::escape($guid)
);
}
return true;
}
- /**
- * @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 static function constructLikeBody($contact, $parent_item, $guid)
- {
- $bodyverb = L10n::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=".System::baseUrl()."/display/".urlencode($guid)."]".L10n::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 static function constructLikeObject($importer, $parent_item)
- {
- $objtype = ACTIVITY_OBJ_NOTE;
- $link = '<link rel="alternate" type="text/html" href="'.System::baseUrl()."/display/".$importer["nickname"]."/".$parent_item["id"].'" />';
- $parent_body = $parent_item["body"];
-
- $xmldata = ["object" => ["type" => $objtype,
- "local" => "1",
- "id" => $parent_item["uri"],
- "link" => $link,
- "title" => "",
- "content" => $parent_body]];
-
- return XML::fromArray($xmldata, $xml, true);
- }
-
/**
* @brief Processes "like" messages
*
*
* @return int The message id of the generated like or "false" if there was an error
*/
- private static function receiveLike($importer, $sender, $data)
+ private static function receiveLike(array $importer, $sender, $data)
{
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
$datarray["guid"] = $guid;
$datarray["uri"] = self::getUriFromGuid($author, $guid);
- $datarray["type"] = "activity";
$datarray["verb"] = $verb;
$datarray["gravity"] = GRAVITY_ACTIVITY;
$datarray["parent-uri"] = $parent_item["uri"];
$datarray["object-type"] = ACTIVITY_OBJ_NOTE;
- $datarray["object"] = self::constructLikeObject($importer, $parent_item);
- $datarray["body"] = self::constructLikeBody($contact, $parent_item, $guid);
+ $datarray["body"] = $verb;
+
+ // Diaspora doesn't provide a date for likes
+ $datarray["changed"] = $datarray["created"] = $datarray["edited"] = DateTimeFormat::utcNow();
// like on comments have the comment as parent. So we need to fetch the toplevel parent
if ($parent_item["id"] != $parent_item["parent"]) {
*
* @return bool Success?
*/
- private static function receiveMessage($importer, $data)
+ private static function receiveMessage(array $importer, $data)
{
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
$c = q(
"SELECT * FROM `conv` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
intval($importer["uid"]),
- dbesc($conversation_guid)
+ DBA::escape($conversation_guid)
);
if ($c) {
$conversation = $c[0];
$body = self::replacePeopleGuid($body, $person["url"]);
- dba::lock('mail');
+ DBA::lock('mail');
$r = q(
"SELECT `id` FROM `mail` WHERE `guid` = '%s' AND `uid` = %d LIMIT 1",
- dbesc($guid),
+ DBA::escape($guid),
intval($importer["uid"])
);
- if (DBM::is_result($r)) {
+ if (DBA::isResult($r)) {
logger("duplicate message already delivered.", LOGGER_DEBUG);
return false;
}
"INSERT INTO `mail` (`uid`, `guid`, `convid`, `from-name`,`from-photo`,`from-url`,`contact-id`,`title`,`body`,`seen`,`reply`,`uri`,`parent-uri`,`created`)
VALUES ( %d, '%s', %d, '%s', '%s', '%s', %d, '%s', '%s', %d, %d, '%s','%s','%s')",
intval($importer["uid"]),
- dbesc($guid),
+ DBA::escape($guid),
intval($conversation["id"]),
- dbesc($person["name"]),
- dbesc($person["photo"]),
- dbesc($person["url"]),
+ DBA::escape($person["name"]),
+ DBA::escape($person["photo"]),
+ DBA::escape($person["url"]),
intval($contact["id"]),
- dbesc($conversation["subject"]),
- dbesc($body),
+ DBA::escape($conversation["subject"]),
+ DBA::escape($body),
0,
1,
- dbesc($message_uri),
- dbesc($author.":".$conversation["guid"]),
- dbesc($created_at)
+ DBA::escape($message_uri),
+ DBA::escape($author.":".$conversation["guid"]),
+ DBA::escape($created_at)
);
- dba::unlock();
+ DBA::unlock();
- dba::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $conversation["id"]]);
+ DBA::update('conv', ['updated' => DateTimeFormat::utcNow()], ['id' => $conversation["id"]]);
return true;
}
*
* @return bool always true
*/
- private static function receiveParticipation($importer, $data)
+ private static function receiveParticipation(array $importer, $data)
{
$author = strtolower(notags(unxmlify($data->author)));
$parent_guid = notags(unxmlify($data->parent_guid));
}
$item = Item::selectFirst(['id'], ['guid' => $parent_guid, 'origin' => true, 'private' => false]);
- if (!DBM::is_result($item)) {
+ if (!DBA::isResult($item)) {
logger('Item not found, no origin or private: '.$parent_guid);
return false;
}
logger('Received participation for ID: '.$item['id'].' - Contact: '.$contact_id.' - Server: '.$server, LOGGER_DEBUG);
- if (!dba::exists('participation', ['iid' => $item['id'], 'server' => $server])) {
- dba::insert('participation', ['iid' => $item['id'], 'cid' => $contact_id, 'fid' => $person['id'], 'server' => $server]);
+ if (!DBA::exists('participation', ['iid' => $item['id'], 'server' => $server])) {
+ DBA::insert('participation', ['iid' => $item['id'], 'cid' => $contact_id, 'fid' => $person['id'], 'server' => $server]);
}
// Send all existing comments and likes to the requesting server
- $comments = Item::select(['id', 'verb', 'self'], ['parent' => $item['id']]);
+ $comments = Item::select(['id', 'parent', 'verb', 'self'], ['parent' => $item['id']]);
while ($comment = Item::fetch($comments)) {
if ($comment['id'] == $comment['parent']) {
continue;
logger("Send ".$cmd." for item ".$comment['id']." to contact ".$contact_id, LOGGER_DEBUG);
Worker::add(PRIORITY_HIGH, 'Delivery', $cmd, $comment['id'], $contact_id);
}
- dba::close($comments);
+ DBA::close($comments);
return true;
}
*
* @return bool always true
*/
- private static function receivePhoto($importer, $data)
+ private static function receivePhoto(array $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 bool always true
*/
- private static function receivePollParticipation($importer, $data)
+ private static function receivePollParticipation(array $importer, $data)
{
// We don't support polls by now
return true;
*
* @return bool Success
*/
- private static function receiveProfile($importer, $data)
+ private static function receiveProfile(array $importer, $data)
{
$author = strtolower(notags(unxmlify($data->author)));
$fields['bd'] = $birthday;
}
- dba::update('contact', $fields, ['id' => $contact['id']]);
+ DBA::update('contact', $fields, ['id' => $contact['id']]);
$gcontact = ["url" => $contact["url"], "network" => NETWORK_DIASPORA, "generation" => 2,
"photo" => $image_url, "name" => $name, "location" => $location,
* @param array $contact The contact that send the request
* @return void
*/
- private static function receiveRequestMakeFriend($importer, $contact)
+ private static function receiveRequestMakeFriend(array $importer, array $contact)
{
$a = get_app();
if ($contact["rel"] == CONTACT_IS_SHARING) {
- dba::update(
+ DBA::update(
'contact',
['rel' => CONTACT_IS_FRIEND, 'writable' => true],
['id' => $contact["id"], 'uid' => $importer["uid"]]
*
* @return bool Success
*/
- private static function receiveContactRequest($importer, $data)
+ private static function receiveContactRequest(array $importer, $data)
{
$author = unxmlify($data->author);
$recipient = unxmlify($data->recipient);
"INSERT INTO `contact` (`uid`, `network`,`addr`,`created`,`url`,`nurl`,`batch`,`name`,`nick`,`photo`,`pubkey`,`notify`,`poll`,`blocked`,`priority`)
VALUES (%d, '%s', '%s', '%s', '%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,%d)",
intval($importer["uid"]),
- dbesc($ret["network"]),
- dbesc($ret["addr"]),
+ DBA::escape($ret["network"]),
+ DBA::escape($ret["addr"]),
DateTimeFormat::utcNow(),
- dbesc($ret["url"]),
- dbesc(normalise_link($ret["url"])),
- dbesc($batch),
- dbesc($ret["name"]),
- dbesc($ret["nick"]),
- dbesc($ret["photo"]),
- dbesc($ret["pubkey"]),
- dbesc($ret["notify"]),
- dbesc($ret["poll"]),
+ DBA::escape($ret["url"]),
+ DBA::escape(normalise_link($ret["url"])),
+ DBA::escape($batch),
+ DBA::escape($ret["name"]),
+ DBA::escape($ret["nick"]),
+ DBA::escape($ret["photo"]),
+ DBA::escape($ret["pubkey"]),
+ DBA::escape($ret["notify"]),
+ DBA::escape($ret["poll"]),
1,
2
);
intval($contact_record["id"]),
0,
0,
- dbesc(L10n::t("Sharing notification from Diaspora network")),
- dbesc($hash),
- dbesc(DateTimeFormat::utcNow())
+ DBA::escape(L10n::t("Sharing notification from Diaspora network")),
+ DBA::escape($hash),
+ DBA::escape(DateTimeFormat::utcNow())
);
} else {
// automatic friend approval
WHERE `id` = %d
",
intval($new_relation),
- dbesc(DateTimeFormat::utcNow()),
- dbesc(DateTimeFormat::utcNow()),
+ DBA::escape(DateTimeFormat::utcNow()),
+ DBA::escape(DateTimeFormat::utcNow()),
intval($contact_record["id"])
);
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
$item = Item::selectFirst($fields, $condition);
- if (DBM::is_result($item)) {
+ if (DBA::isResult($item)) {
logger("reshared message ".$guid." already exists on system.");
// Maybe it is already a reshared item?
}
}
- if (!DBM::is_result($item)) {
+ if (!DBA::isResult($item)) {
if (empty($orig_author)) {
logger('Empty author for guid ' . $guid . '. Quitting.');
return false;
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
$item = Item::selectFirst($fields, $condition);
- if (DBM::is_result($item)) {
+ if (DBA::isResult($item)) {
// If it is a reshared post from another network then reformat to avoid display problems with two share elements
if (self::isReshare($item["body"], false)) {
$item["body"] = Markdown::toBBCode(BBCode::toMarkdown($item["body"]));
*
* @return int the message id
*/
- private static function receiveReshare($importer, $data, $xml)
+ private static function receiveReshare(array $importer, $data, $xml)
{
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
*
* @return bool success
*/
- private static function itemRetraction($importer, $contact, $data)
+ private static function itemRetraction(array $importer, array $contact, $data)
{
$author = notags(unxmlify($data->author));
$target_guid = notags(unxmlify($data->target_guid));
}
// Fetch items that are about to be deleted
- $fields = ['uid', 'id', 'parent', 'parent-uri', 'author-link'];
+ $fields = ['uid', 'id', 'parent', 'parent-uri', 'author-link', 'file'];
// When we receive a public retraction, we delete every item that we find.
if ($importer['uid'] == 0) {
- $condition = ["`guid` = ? AND NOT `file` LIKE '%%[%%' AND NOT `deleted`", $target_guid];
+ $condition = ['guid' => $target_guid, 'deleted' => false];
} else {
- $condition = ["`guid` = ? AND `uid` = ? AND NOT `file` LIKE '%%[%%' AND NOT `deleted`", $target_guid, $importer['uid']];
+ $condition = ['guid' => $target_guid, 'deleted' => false, 'uid' => $importer['uid']];
}
+
$r = Item::select($fields, $condition);
- if (!DBM::is_result($r)) {
+ if (!DBA::isResult($r)) {
logger("Target guid ".$target_guid." was not found on this system for user ".$importer['uid'].".");
return false;
}
while ($item = Item::fetch($r)) {
+ if (strstr($item['file'], '[')) {
+ logger("Target guid " . $target_guid . " for user " . $item['uid'] . " is filed. So it won't be deleted.", LOGGER_DEBUG);
+ continue;
+ }
+
// Fetch the parent item
$parent = Item::selectFirst(['author-link'], ['id' => $item["parent"]]);
*
* @return bool Success
*/
- private static function receiveRetraction($importer, $sender, $data)
+ private static function receiveRetraction(array $importer, $sender, $data)
{
$target_type = notags(unxmlify($data->target_type));
return false;
}
+ if (!$contact) {
+ $contact = [];
+ }
+
logger("Got retraction for ".$target_type.", sender ".$sender." and user ".$importer["uid"], LOGGER_DEBUG);
switch ($target_type) {
*
* @return int The message id of the newly created item
*/
- private static function receiveStatusMessage($importer, $data, $xml)
+ private static function receiveStatusMessage(array $importer, $data, $xml)
{
$author = notags(unxmlify($data->author));
$guid = notags(unxmlify($data->guid));
*
* @return string the handle in the format user@domain.tld
*/
- private static function myHandle($contact)
+ private static function myHandle(array $contact)
{
- if ($contact["addr"] != "") {
+ if (!empty($contact["addr"])) {
return $contact["addr"];
}
$nick = $contact["nick"];
}
- return $nick."@".substr(System::baseUrl(), strpos(System::baseUrl(), "://") + 3);
+ return $nick . "@" . substr(System::baseUrl(), strpos(System::baseUrl(), "://") + 3);
}
*
* @return string The encrypted data
*/
- public static function encodePrivateData($msg, $user, $contact, $prvkey, $pubkey)
+ public static function encodePrivateData($msg, array $user, array $contact, $prvkey, $pubkey)
{
logger("Message: ".$msg, LOGGER_DATA);
*
* @return string The envelope
*/
- public static function buildMagicEnvelope($msg, $user)
+ public static function buildMagicEnvelope($msg, array $user)
{
$b64url_data = base64url_encode($msg);
$data = str_replace(["\n", "\r", " ", "\t"], ["", "", "", ""], $b64url_data);
*
* @return string The message that will be transmitted to other servers
*/
- public static function buildMessage($msg, $user, $contact, $prvkey, $pubkey, $public = false)
+ public static function buildMessage($msg, array $user, array $contact, $prvkey, $pubkey, $public = false)
{
// The message is put into an envelope with the sender's signature
$envelope = self::buildMagicEnvelope($msg, $user);
*
* @return int Result of the transmission
*/
- public static function transmit($owner, $contact, $envelope, $public_batch, $queue_run = false, $guid = "", $no_queue = false)
+ public static function transmit(array $owner, array $contact, $envelope, $public_batch, $queue_run = false, $guid = "", $no_queue = false)
{
$a = get_app();
*
* @return int Result of the transmission
*/
- private static function buildAndTransmit($owner, $contact, $type, $message, $public_batch = false, $guid = "", $spool = false)
+ private static function buildAndTransmit(array $owner, array $contact, $type, $message, $public_batch = false, $guid = "", $spool = false)
{
$msg = self::buildPostXml($type, $message);
logger('send guid '.$guid, LOGGER_DEBUG);
// Fallback if the private key wasn't transmitted in the expected field
- if ($owner['uprvkey'] == "") {
+ if (empty($owner['uprvkey'])) {
$owner['uprvkey'] = $owner['prvkey'];
}
*
* @return int The result of the transmission
*/
- private static function sendParticipation($contact, $item)
+ private static function sendParticipation(array $contact, array $item)
{
// Don't send notifications for private postings
if ($item['private']) {
// If the item belongs to a user, we take this user id.
if ($item['uid'] == 0) {
$condition = ['verified' => true, 'blocked' => false, 'account_removed' => false, 'account_expired' => false];
- $first_user = dba::selectFirst('user', ['uid'], $condition);
+ $first_user = DBA::selectFirst('user', ['uid'], $condition);
$owner = User::getOwnerDataById($first_user['uid']);
} else {
$owner = User::getOwnerDataById($item['uid']);
$author = self::myHandle($owner);
$message = ["author" => $author,
- "guid" => get_guid(32),
+ "guid" => System::createGUID(32),
"parent_type" => "Post",
"parent_guid" => $item["guid"]];
*
* @return int The result of the transmission
*/
- public static function sendAccountMigration($owner, $contact, $uid)
+ public static function sendAccountMigration(array $owner, array $contact, $uid)
{
$old_handle = PConfig::get($uid, 'system', 'previous_addr');
$profile = self::createProfileData($uid);
*
* @return int The result of the transmission
*/
- public static function sendShare($owner, $contact)
+ public static function sendShare(array $owner, array $contact)
{
/**
* @todo support the different possible combinations of "following" and "sharing"
*
* @return int The result of the transmission
*/
- public static function sendUnshare($owner, $contact)
+ public static function sendUnshare(array $owner, array $contact)
{
$message = ["author" => self::myHandle($owner),
"recipient" => $contact["addr"],
$guid = "";
preg_match("/guid='(.*?)'/ism", $attributes, $matches);
- if ($matches[1] != "") {
+ if (!empty($matches[1])) {
$guid = $matches[1];
}
preg_match('/guid="(.*?)"/ism', $attributes, $matches);
- if ($matches[1] != "") {
+ if (!empty($matches[1])) {
$guid = $matches[1];
}
if (($guid != "") && $complete) {
$condition = ['guid' => $guid, 'network' => [NETWORK_DFRN, NETWORK_DIASPORA]];
$item = Item::selectFirst(['contact-id'], $condition);
- if (DBM::is_result($item)) {
+ if (DBA::isResult($item)) {
$ret= [];
$ret["root_handle"] = self::handleFromContact($item["contact-id"]);
$ret["root_guid"] = $guid;
$profile = "";
preg_match("/profile='(.*?)'/ism", $attributes, $matches);
- if ($matches[1] != "") {
+ if (!empty($matches[1])) {
$profile = $matches[1];
}
preg_match('/profile="(.*?)"/ism', $attributes, $matches);
- if ($matches[1] != "") {
+ if (!empty($matches[1])) {
$profile = $matches[1];
}
private static function buildEvent($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)) {
+ if (!DBA::isResult($r)) {
return [];
}
$eventdata = [];
$r = q("SELECT `timezone` FROM `user` WHERE `uid` = %d", intval($event['uid']));
- if (!DBM::is_result($r)) {
+ if (!DBA::isResult($r)) {
return [];
}
$user = $r[0];
$r = q("SELECT `addr`, `nick` FROM `contact` WHERE `uid` = %d AND `self`", intval($event['uid']));
- if (!DBM::is_result($r)) {
+ if (!DBA::isResult($r)) {
return [];
}
* 'type' -> Message type ("status_message" or "reshare")
* 'message' -> Array of XML elements of the status
*/
- public static function buildStatus($item, $owner)
+ public static function buildStatus(array $item, array $owner)
{
$cachekey = "diaspora:buildStatus:".$item['guid'];
*
* @return int The result of the transmission
*/
- public static function sendStatus($item, $owner, $contact, $public_batch = false)
+ public static function sendStatus(array $item, array $owner, array $contact, $public_batch = false)
{
$status = self::buildStatus($item, $owner);
*
* @return array The data for a "like"
*/
- private static function constructLike($item, $owner)
+ private static function constructLike(array $item, array $owner)
{
$parent = Item::selectFirst(['guid', 'uri', 'parent-uri'], ['uri' => $item["thr-parent"]]);
- if (!DBM::is_result($parent)) {
+ if (!DBA::isResult($parent)) {
return false;
}
*
* @return array The data for an "EventParticipation"
*/
- private static function constructAttend($item, $owner)
+ private static function constructAttend(array $item, array $owner)
{
$parent = Item::selectFirst(['guid', 'uri', 'parent-uri'], ['uri' => $item["thr-parent"]]);
- if (!DBM::is_result($parent)) {
+ if (!DBA::isResult($parent)) {
return false;
}
*
* @return array The data for a comment
*/
- private static function constructComment($item, $owner)
+ private static function constructComment(array $item, array $owner)
{
$cachekey = "diaspora:constructComment:".$item['guid'];
}
$parent = Item::selectFirst(['guid'], ['id' => $item["parent"], 'parent' => $item["parent"]]);
- if (!DBM::is_result($parent)) {
+ if (!DBA::isResult($parent)) {
return false;
}
*
* @return int The result of the transmission
*/
- public static function sendFollowup($item, $owner, $contact, $public_batch = false)
+ public static function sendFollowup(array $item, array $owner, array $contact, $public_batch = false)
{
if (in_array($item['verb'], [ACTIVITY_ATTEND, ACTIVITY_ATTENDNO, ACTIVITY_ATTENDMAYBE])) {
$message = self::constructAttend($item, $owner);
*
* @return string The message
*/
- private static function messageFromSignature($item, $signature)
+ private static function messageFromSignature(array $item, array $signature)
{
// Split the signed text
$signed_parts = explode(";", $signature['signed_text']);
*
* @return int The result of the transmission
*/
- public static function sendRelay($item, $owner, $contact, $public_batch = false)
+ public static function sendRelay(array $item, array $owner, array $contact, $public_batch = false)
{
if ($item["deleted"]) {
return self::sendRetraction($item, $owner, $contact, $public_batch, true);
*
* @return int The result of the transmission
*/
- public static function sendRetraction($item, $owner, $contact, $public_batch = false, $relay = false)
+ public static function sendRetraction(array $item, array $owner, array $contact, $public_batch = false, $relay = false)
{
$itemaddr = self::handleFromContact($item["contact-id"], $item["author-id"]);
*
* @return int The result of the transmission
*/
- public static function sendMail($item, $owner, $contact)
+ public static function sendMail(array $item, array $owner, array $contact)
{
$myaddr = self::myHandle($owner);
intval($item["uid"])
);
- if (!DBM::is_result($r)) {
+ if (!DBA::isResult($r)) {
logger("conversation not found.");
return;
}
$recips = q(
"SELECT `id`,`name`,`network`,`pubkey`,`notify` FROM `contact` WHERE `network` = '%s'
AND `uid` = %d AND `rel` != %d",
- dbesc(NETWORK_DIASPORA),
+ DBA::escape(NETWORK_DIASPORA),
intval($uid),
intval(CONTACT_IS_SHARING)
);
*
* @return bool Success
*/
- public static function storeLikeSignature($contact, $post_id)
+ public static function storeLikeSignature(array $contact, $post_id)
{
// Is the contact the owner? Then fetch the private key
if (!$contact['self'] || ($contact['uid'] == 0)) {
}
$r = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($contact['uid']));
- if (!DBM::is_result($r)) {
+ if (!DBA::isResult($r)) {
return false;
}
$contact["uprvkey"] = $r[0]['prvkey'];
$item = Item::selectFirst([], ['id' => $post_id]);
- if (!DBM::is_result($item)) {
+ if (!DBA::isResult($item)) {
return false;
}
* Now store the signature more flexible to dynamically support new fields.
* This will break Diaspora compatibility with Friendica versions prior to 3.5.
*/
- dba::insert('sign', ['iid' => $post_id, 'signed_text' => json_encode($message)]);
+ DBA::insert('sign', ['iid' => $post_id, 'signed_text' => json_encode($message)]);
logger('Stored diaspora like signature');
return true;
*
* @return bool Success
*/
- public static function storeCommentSignature($item, $contact, $uprvkey, $message_id)
+ public static function storeCommentSignature(array $item, array $contact, $uprvkey, $message_id)
{
if ($uprvkey == "") {
logger('No private key, so not storing comment signature', LOGGER_DEBUG);
* Now store the signature more flexible to dynamically support new fields.
* This will break Diaspora compatibility with Friendica versions prior to 3.5.
*/
- dba::insert('sign', ['iid' => $message_id, 'signed_text' => json_encode($message)]);
+ DBA::insert('sign', ['iid' => $message_id, 'signed_text' => json_encode($message)]);
logger('Stored diaspora comment signature');
return true;