X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=src%2FProtocol%2FDiaspora.php;h=7c4e19d923a7dda098576c1f9ffb350bef954200;hb=dbad46c37847f894312c0f1318a21f5ce3606cb0;hp=b3e6956f5149c76ad31d8769acf2e7d874a06d84;hpb=eba46e786a5b160af690f15d3a3e42f6b9b1e3e4;p=friendica.git diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index b3e6956f51..7c4e19d923 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -1,11 +1,22 @@ . * - * The new protocol is described here: http://diaspora.github.io/diaspora_federation/index.html - * This implementation here interprets the old and the new protocol and sends the new one. - * In the future we will remove most stuff from "validPosting" and interpret only the new protocol. */ namespace Friendica\Protocol; @@ -13,11 +24,8 @@ namespace Friendica\Protocol; use Friendica\Content\Feature; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\Markdown; -use Friendica\Core\Cache\Cache; -use Friendica\Core\Config; -use Friendica\Core\L10n; +use Friendica\Core\Cache\Duration; use Friendica\Core\Logger; -use Friendica\Core\PConfig; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Core\Worker; @@ -27,9 +35,12 @@ use Friendica\Model\Contact; use Friendica\Model\Conversation; use Friendica\Model\GContact; use Friendica\Model\Item; +use Friendica\Model\ItemURI; use Friendica\Model\ItemDeliveryData; use Friendica\Model\Mail; use Friendica\Model\Profile; +use Friendica\Model\Tag; +use Friendica\Model\Term; use Friendica\Model\User; use Friendica\Network\Probe; use Friendica\Util\Crypto; @@ -42,8 +53,7 @@ use Friendica\Worker\Delivery; use SimpleXMLElement; /** - * @brief This class contain functions to create and send Diaspora XML files - * + * This class contain functions to create and send Diaspora XML files */ class Diaspora { @@ -78,7 +88,7 @@ class Diaspora } /** - * @brief Return a list of relay servers + * Return a list of relay servers * * The list contains not only the official relays but also servers that we serve directly * @@ -93,7 +103,7 @@ class Diaspora $serverlist = []; // Fetching relay servers - $serverdata = Config::get("system", "relay_server"); + $serverdata = DI::config()->get("system", "relay_server"); if (!empty($serverdata)) { $servers = explode(",", $serverdata); @@ -102,7 +112,7 @@ class Diaspora } } - if (Config::get("system", "relay_directly", false)) { + if (DI::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 (!DBA::isResult($parent)) { @@ -116,7 +126,7 @@ class Diaspora } // All tags of the current post - $condition = ['otype' => TERM_OBJ_POST, 'type' => TERM_HASHTAG, 'oid' => $parent['parent']]; + $condition = ['otype' => Term::OBJECT_TYPE_POST, 'type' => Term::HASHTAG, 'oid' => $parent['parent']]; $tags = DBA::select('term', ['term'], $condition); $taglist = []; while ($tag = DBA::fetch($tags)) { @@ -168,7 +178,7 @@ class Diaspora } /** - * @brief Return a contact for a given server address or creates a dummy entry + * Return a contact for a given server address or creates a dummy entry * * @param string $server_url The url of the server * @param array $fields Fieldlist @@ -201,7 +211,7 @@ class Diaspora } /** - * @brief Update or insert a relay contact + * Update or insert a relay contact * * @param string $server_url The url of the server * @param array $network_fields Optional network specific fields @@ -235,7 +245,7 @@ class Diaspora } /** - * @brief Return a list of participating contacts for a thread + * Return a list of participating contacts for a thread * * This is used for the participation feature. * One of the parameters is a contact array. @@ -249,27 +259,13 @@ class Diaspora */ public static function participantsForThread($thread, array $contacts) { - $r = DBA::p("SELECT `contact`.`batch`, `contact`.`id`, `contact`.`url`, `contact`.`name`, `contact`.`network`, `contact`.`protocol`, - `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` = ? AND NOT `contact`.`archive`", $thread); - - while ($contact = DBA::fetch($r)) { - if (!empty($contact['fnetwork'])) { - $contact['network'] = $contact['fnetwork']; - } - unset($contact['fnetwork']); + $participation = DBA::select('participation-view', [], ['iid' => $thread]); + while ($contact = DBA::fetch($participation)) { if (empty($contact['protocol'])) { $contact['protocol'] = $contact['network']; } - if (empty($contact['batch']) && !empty($contact['fbatch'])) { - $contact['batch'] = $contact['fbatch']; - } - unset($contact['fbatch']); - $exists = false; foreach ($contacts as $entry) { if ($entry['batch'] == $contact['batch']) { @@ -281,13 +277,14 @@ class Diaspora $contacts[] = $contact; } } - DBA::close($r); + + DBA::close($participation); return $contacts; } /** - * @brief repairs a signature that was double encoded + * repairs a signature that was double encoded * * The function is unused at the moment. It was copied from the old implementation. * @@ -318,7 +315,7 @@ class Diaspora } /** - * @brief verify the envelope and return the verified data + * verify the envelope and return the verified data * * @param string $envelope The magic envelope * @@ -328,7 +325,7 @@ class Diaspora */ private static function verifyMagicEnvelope($envelope) { - $basedom = XML::parseString($envelope); + $basedom = XML::parseString($envelope, true); if (!is_object($basedom)) { Logger::log("Envelope is no XML file"); @@ -383,7 +380,7 @@ class Diaspora } /** - * @brief encrypts data via AES + * encrypts data via AES * * @param string $key The AES key * @param string $iv The IV (is used for CBC encoding) @@ -397,7 +394,7 @@ class Diaspora } /** - * @brief decrypts data via AES + * decrypts data via AES * * @param string $key The AES key * @param string $iv The IV (is used for CBC encoding) @@ -411,7 +408,7 @@ class Diaspora } /** - * @brief: Decodes incoming Diaspora message in the new format + * Decodes incoming Diaspora message in the new format * * @param string $raw raw post message * @param string $privKey The private key of the importer @@ -454,7 +451,7 @@ class Diaspora $xml = $raw; } - $basedom = XML::parseString($xml); + $basedom = XML::parseString($xml, true); if (!is_object($basedom)) { Logger::log('Received data does not seem to be an XML. Discarding. '.$xml); @@ -517,7 +514,7 @@ class Diaspora } /** - * @brief: Decodes incoming Diaspora message in the deprecated format + * Decodes incoming Diaspora message in the deprecated format * * @param string $xml urldecoded Diaspora salmon * @param string $privKey The private key of the importer @@ -660,7 +657,7 @@ class Diaspora /** - * @brief Dispatches public messages and find the fitting receivers + * Dispatches public messages and find the fitting receivers * * @param array $msg The post that will be dispatched * @@ -670,7 +667,7 @@ class Diaspora */ public static function dispatchPublic($msg) { - $enabled = intval(Config::get("system", "diaspora_enabled")); + $enabled = intval(DI::config()->get("system", "diaspora_enabled")); if (!$enabled) { Logger::log("diaspora is disabled"); return false; @@ -688,7 +685,7 @@ class Diaspora } /** - * @brief Dispatches the different message types to the different functions + * Dispatches the different message types to the different functions * * @param array $importer Array of the importer user * @param array $msg The post that will be dispatched @@ -793,7 +790,7 @@ class Diaspora } /** - * @brief Checks if a posting is valid and fetches the data fields. + * Checks if a posting is valid and fetches the data fields. * * This function does not only check the signature. * It also does the conversion between the old and the new diaspora format. @@ -946,7 +943,7 @@ class Diaspora } /** - * @brief Fetches the public key for a given handle + * Fetches the public key for a given handle * * @param string $handle The handle * @@ -969,7 +966,7 @@ class Diaspora } /** - * @brief Fetches data for a given handle + * Fetches data for a given handle * * @param string $handle The handle * @param boolean $update true = always update, false = never update, null = update when not found or outdated @@ -1023,7 +1020,7 @@ class Diaspora } /** - * @brief Updates the fcontact table + * Updates the fcontact table * * @param array $arr The fcontact data * @throws \Exception @@ -1044,7 +1041,7 @@ class Diaspora } /** - * @brief get a handle (user@domain.tld) from a given contact id + * get a handle (user@domain.tld) from a given contact id * * @param int $contact_id The id in the contact table * @param int $pcontact_id The id in the contact table (Used for the public contact) @@ -1091,7 +1088,7 @@ class Diaspora } /** - * @brief get a url (scheme://domain.tld/u/user) from a given Diaspora* + * get a url (scheme://domain.tld/u/user) from a given Diaspora* * fcontact guid * * @param mixed $fcontact_guid Hexadecimal string guid @@ -1117,7 +1114,7 @@ class Diaspora } /** - * @brief Get a contact id for a given handle + * Get a contact id for a given handle * * @todo Move to Friendica\Model\Contact * @@ -1161,7 +1158,7 @@ class Diaspora } /** - * @brief Check if posting is allowed for this contact + * Check if posting is allowed for this contact * * @param array $importer Array of the importer user * @param array $contact The contact that is checked @@ -1214,7 +1211,7 @@ class Diaspora } /** - * @brief Fetches the contact id for a handle and checks if posting is allowed + * Fetches the contact id for a handle and checks if posting is allowed * * @param array $importer Array of the importer user * @param string $handle The checked handle in the format user@domain.tld @@ -1246,7 +1243,7 @@ class Diaspora } /** - * @brief Does the message already exists on the system? + * Does the message already exists on the system? * * @param int $uid The user id * @param string $guid The guid of the message @@ -1266,7 +1263,7 @@ class Diaspora } /** - * @brief Checks for links to posts in a message + * Checks for links to posts in a message * * @param array $item The item array * @return void @@ -1292,7 +1289,7 @@ class Diaspora } /** - * @brief Checks for relative /people/* links in an item body to match local + * Checks for relative /people/* links in an item body to match local * contacts or prepends the remote host taken from the author link. * * @param string $body The item body to replace links from @@ -1328,7 +1325,7 @@ class Diaspora } /** - * @brief sub function of "fetchGuid" which checks for links in messages + * sub function of "fetchGuid" which checks for links in messages * * @param array $match array containing a link that has to be checked for a message link * @param array $item The item array @@ -1344,7 +1341,7 @@ class Diaspora } /** - * @brief Fetches an item with a given guid from a given server + * Fetches an item with a given guid from a given server * * @param string $guid the message guid * @param string $server The server address @@ -1379,7 +1376,7 @@ class Diaspora } /** - * @brief Fetches a message from a server + * Fetches a message from a server * * @param string $guid message guid * @param string $server The url of the server @@ -1458,7 +1455,7 @@ class Diaspora } /** - * @brief Fetches an item with a given URL + * Fetches an item with a given URL * * @param string $url the message url * @@ -1469,7 +1466,8 @@ class Diaspora public static function fetchByURL($url, $uid = 0) { // Check for Diaspora (and Friendica) typical paths - if (!preg_match("=(https?://.+)/(?:posts|display)/([a-zA-Z0-9-_@.:%]+[a-zA-Z0-9])=i", $url, $matches)) { + if (!preg_match("=(https?://.+)/(?:posts|display|objects)/([a-zA-Z0-9-_@.:%]+[a-zA-Z0-9])=i", $url, $matches)) { + Logger::info('Invalid url', ['url' => $url]); return false; } @@ -1477,21 +1475,26 @@ class Diaspora $item = Item::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]); if (DBA::isResult($item)) { + Logger::info('Found', ['id' => $item['id']]); return $item['id']; } - self::storeByGuid($guid, $matches[1], $uid); + Logger::info('Fetch GUID from origin', ['guid' => $guid, 'server' => $matches[1]]); + $ret = self::storeByGuid($guid, $matches[1], $uid); + Logger::info('Result', ['ret' => $ret]); $item = Item::selectFirst(['id'], ['guid' => $guid, 'uid' => $uid]); if (DBA::isResult($item)) { + Logger::info('Found', ['id' => $item['id']]); return $item['id']; } else { + Logger::info('Not found', ['guid' => $guid, 'uid' => $uid]); return false; } } /** - * @brief Fetches the item record of a given guid + * Fetches the item record of a given guid * * @param int $uid The user id * @param string $guid message guid @@ -1535,7 +1538,7 @@ class Diaspora } /** - * @brief returns contact details + * returns contact details * * @param array $def_contact The default contact if the person isn't found * @param array $person The record of the person @@ -1562,19 +1565,19 @@ class Diaspora } /** - * @brief Is the profile a hubzilla profile? + * Is the profile a hubzilla profile? * * @param string $url The profile link * * @return bool is it a hubzilla server? */ - public static function isRedmatrix($url) + private static function isHubzilla($url) { - return(strstr($url, "/channel/")); + return(strstr($url, '/channel/')); } /** - * @brief Generate a post link with a given handle and message guid + * Generate a post link with a given handle and message guid * * @param string $addr The user handle * @param string $guid message guid @@ -1587,33 +1590,59 @@ class Diaspora private static function plink($addr, $guid, $parent_guid = '') { $contact = Contact::getDetailsByAddr($addr); + if (empty($contact)) { + Logger::info('No contact data for address', ['addr' => $addr]); + return ''; + } - // Fallback - if (!$contact) { - if ($parent_guid != '') { - return "https://" . substr($addr, strpos($addr, "@") + 1) . "/posts/" . $parent_guid . "#" . $guid; - } else { - return "https://" . substr($addr, strpos($addr, "@") + 1) . "/posts/" . $guid; + if (empty($contact['baseurl'])) { + $contact['baseurl'] = 'https://' . substr($addr, strpos($addr, '@') + 1); + Logger::info('Create baseurl from address', ['baseurl' => $contact['baseurl'], 'url' => $contact['url']]); + } + + $platform = ''; + $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => Strings::normaliseLink($contact['baseurl'])]); + if (!empty($gserver['platform'])) { + $platform = strtolower($gserver['platform']); + Logger::info('Detected platform', ['platform' => $platform, 'url' => $contact['url']]); + } + + if (!in_array($platform, ['diaspora', 'friendica', 'hubzilla', 'socialhome'])) { + if (self::isHubzilla($contact['url'])) { + Logger::info('Detected unknown platform as Hubzilla', ['platform' => $platform, 'url' => $contact['url']]); + $platform = 'hubzilla'; + } elseif ($contact['network'] == Protocol::DFRN) { + Logger::info('Detected unknown platform as Friendica', ['platform' => $platform, 'url' => $contact['url']]); + $platform = 'friendica'; } } - if ($contact["network"] == Protocol::DFRN) { - return str_replace("/profile/" . $contact["nick"] . "/", "/display/" . $guid, $contact["url"] . "/"); + if ($platform == 'friendica') { + return str_replace('/profile/' . $contact['nick'] . '/', '/display/' . $guid, $contact['url'] . '/'); + } + + if ($platform == 'hubzilla') { + return $contact['baseurl'] . '/item/' . $guid; + } + + if ($platform == 'socialhome') { + return $contact['baseurl'] . '/content/' . $guid; } - if (self::isRedmatrix($contact["url"])) { - return $contact["url"] . "/?mid=" . $guid; + if ($platform != 'diaspora') { + Logger::info('Unknown platform', ['platform' => $platform, 'url' => $contact['url']]); + return ''; } if ($parent_guid != '') { - return "https://" . substr($addr, strpos($addr, "@") + 1) . "/posts/" . $parent_guid . "#" . $guid; + return $contact['baseurl'] . '/posts/' . $parent_guid . '#' . $guid; } else { - return "https://" . substr($addr, strpos($addr, "@") + 1) . "/posts/" . $guid; + return $contact['baseurl'] . '/posts/' . $guid; } } /** - * @brief Receives account migration + * Receives account migration * * @param array $importer Array of the importer user * @param object $data The message object @@ -1676,7 +1705,7 @@ class Diaspora } /** - * @brief Processes an account deletion + * Processes an account deletion * * @param object $data The message object * @@ -1700,7 +1729,7 @@ class Diaspora } /** - * @brief Fetch the uri from our database if we already have this item (maybe from ourselves) + * Fetch the uri from our database if we already have this item (maybe from ourselves) * * @param string $author Author handle * @param string $guid Message guid @@ -1729,7 +1758,7 @@ class Diaspora } /** - * @brief Fetch the guid from our database with a given uri + * Fetch the guid from our database with a given uri * * @param string $uri Message uri * @param string $uid Author handle @@ -1748,7 +1777,7 @@ class Diaspora } /** - * @brief Find the best importer for a comment, like, ... + * Find the best importer for a comment, like, ... * * @param string $guid The guid of the item * @@ -1769,7 +1798,41 @@ class Diaspora } /** - * @brief Processes an incoming comment + * Store the mentions in the tag table + * + * @param integer $uriid + * @param string $text + */ + private static function storeMentions(int $uriid, string $text) + { + preg_match_all('/([@!]){(?:([^}]+?); ?)?([^} ]+)}/', $text, $matches, PREG_SET_ORDER); + if (empty($matches)) { + return; + } + + /* + * Matching values for the preg match + * [1] = mention type (@ or !) + * [2] = name (optional) + * [3] = profile URL + */ + + foreach ($matches as $match) { + if (empty($match)) { + continue; + } + + $person = self::personByHandle($match[3]); + if (empty($person)) { + continue; + } + + Tag::storeByHash($uriid, $match[1], $person['name'] ?: $person['nick'], $person['url']); + } + } + + /** + * Processes an incoming comment * * @param array $importer Array of the importer user * @param string $sender The sender of the message @@ -1838,6 +1901,7 @@ class Diaspora $datarray["guid"] = $guid; $datarray["uri"] = self::getUriFromGuid($author, $guid); + $datarray['uri-id'] = ItemURI::insert(['uri' => $datarray['uri'], 'guid' => $datarray['guid']]); $datarray["verb"] = Activity::POST; $datarray["gravity"] = GRAVITY_COMMENT; @@ -1856,11 +1920,13 @@ class Diaspora $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at; $datarray["plink"] = self::plink($author, $guid, $parent_item['guid']); - $body = Markdown::toBBCode($text); $datarray["body"] = self::replacePeopleGuid($body, $person["url"]); + self::storeMentions($datarray['uri-id'], $text); + Tag::storeRawTagsFromBody($datarray['uri-id'], $datarray["body"]); + self::fetchGuid($datarray); // If we are the origin of the parent we store the original data. @@ -1886,7 +1952,7 @@ class Diaspora } /** - * @brief processes and stores private messages + * processes and stores private messages * * @param array $importer Array of the importer user * @param array $contact The contact of the message @@ -1946,7 +2012,7 @@ class Diaspora } /** - * @brief Processes new private messages (answers to private messages are processed elsewhere) + * Processes new private messages (answers to private messages are processed elsewhere) * * @param array $importer Array of the importer user * @param array $msg Array of the processed message, author handle and key @@ -2005,7 +2071,7 @@ class Diaspora } /** - * @brief Processes "like" messages + * Processes "like" messages * * @param array $importer Array of the importer user * @param string $sender The sender of the message @@ -2117,7 +2183,7 @@ class Diaspora } /** - * @brief Processes private messages + * Processes private messages * * @param array $importer Array of the importer user * @param object $data The message object @@ -2178,7 +2244,7 @@ class Diaspora } /** - * @brief Processes participations - unsupported by now + * Processes participations - unsupported by now * * @param array $importer Array of the importer user * @param object $data The message object @@ -2204,7 +2270,7 @@ class Diaspora return false; } - $item = Item::selectFirst(['id'], ['guid' => $parent_guid, 'origin' => true, 'private' => false]); + $item = Item::selectFirst(['id'], ['guid' => $parent_guid, 'origin' => true, 'private' => [Item::PUBLIC, Item::UNLISTED]]); if (!DBA::isResult($item)) { Logger::log('Item not found, no origin or private: '.$parent_guid); return false; @@ -2242,7 +2308,7 @@ class Diaspora } /** - * @brief Processes photos - unneeded + * Processes photos - unneeded * * @param array $importer Array of the importer user * @param object $data The message object @@ -2257,7 +2323,7 @@ class Diaspora } /** - * @brief Processes poll participations - unssupported + * Processes poll participations - unssupported * * @param array $importer Array of the importer user * @param object $data The message object @@ -2271,7 +2337,7 @@ class Diaspora } /** - * @brief Processes incoming profile updates + * Processes incoming profile updates * * @param array $importer Array of the importer user * @param object $data The message object @@ -2292,7 +2358,6 @@ class Diaspora $name = XML::unescape($data->first_name).((strlen($data->last_name)) ? " ".XML::unescape($data->last_name) : ""); $image_url = XML::unescape($data->image_url); $birthday = XML::unescape($data->birthday); - $gender = XML::unescape($data->gender); $about = Markdown::toBBCode(XML::unescape($data->bio)); $location = Markdown::toBBCode(XML::unescape($data->location)); $searchable = (XML::unescape($data->searchable) == "true"); @@ -2340,8 +2405,7 @@ class Diaspora } $fields = ['name' => $name, 'location' => $location, - 'name-date' => DateTimeFormat::utcNow(), - 'about' => $about, 'gender' => $gender, + 'name-date' => DateTimeFormat::utcNow(), 'about' => $about, 'addr' => $author, 'nick' => $nick, 'keywords' => $keywords, 'unsearchable' => !$searchable, 'sensitive' => $nsfw]; @@ -2355,7 +2419,7 @@ class Diaspora $gcontact = ["url" => $contact["url"], "network" => Protocol::DIASPORA, "generation" => 2, "photo" => $image_url, "name" => $name, "location" => $location, - "about" => $about, "birthday" => $birthday, "gender" => $gender, + "about" => $about, "birthday" => $birthday, "addr" => $author, "nick" => $nick, "keywords" => $keywords, "hide" => !$searchable, "nsfw" => $nsfw]; @@ -2369,7 +2433,7 @@ class Diaspora } /** - * @brief Processes incoming friend requests + * Processes incoming friend requests * * @param array $importer Array of the importer user * @param array $contact The contact that send the request @@ -2388,7 +2452,7 @@ class Diaspora } /** - * @brief Processes incoming sharing notification + * Processes incoming sharing notification * * @param array $importer Array of the importer user * @param object $data The message object @@ -2500,7 +2564,7 @@ class Diaspora } /** - * @brief Fetches a message with a given guid + * Fetches a message with a given guid * * @param string $guid message guid * @param string $orig_author handle of the original post @@ -2518,7 +2582,7 @@ class Diaspora // Do we already have this item? $fields = ['body', 'title', 'attach', 'tag', 'app', 'created', 'object-type', 'uri', 'guid', 'author-name', 'author-link', 'author-avatar']; - $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false]; + $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]]; $item = Item::selectFirst($fields, $condition); if (DBA::isResult($item)) { @@ -2562,7 +2626,7 @@ class Diaspora if ($stored) { $fields = ['body', 'title', 'attach', 'tag', 'app', 'created', 'object-type', 'uri', 'guid', 'author-name', 'author-link', 'author-avatar']; - $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false]; + $condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => [Item::PUBLIC, Item::UNLISTED]]; $item = Item::selectFirst($fields, $condition); if (DBA::isResult($item)) { @@ -2580,7 +2644,7 @@ class Diaspora } /** - * @brief Stores a reshare activity + * Stores a reshare activity * * @param array $item Array of reshare post * @param integer $parent_message_id Id of the parent post @@ -2628,7 +2692,7 @@ class Diaspora } /** - * @brief Processes a reshare message + * Processes a reshare message * * @param array $importer Array of the importer user * @param object $data The message object @@ -2679,6 +2743,7 @@ class Diaspora $datarray["guid"] = $guid; $datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid); + $datarray['uri-id'] = ItemURI::insert(['uri' => $datarray['uri'], 'guid' => $datarray['guid']]); $datarray["verb"] = Activity::POST; $datarray["gravity"] = GRAVITY_PARENT; @@ -2686,6 +2751,8 @@ class Diaspora $datarray["protocol"] = Conversation::PARCEL_DIASPORA; $datarray["source"] = $xml; + /// @todo Copy tag data from original post + $prefix = share_header( $original_item["author-name"], $original_item["author-link"], @@ -2701,12 +2768,14 @@ class Diaspora $datarray["body"] = $prefix.$original_item["body"]."[/share]"; + Tag::storeFromBody($datarray['uri-id'], $datarray["body"]); + $datarray["tag"] = $original_item["tag"]; $datarray["attach"] = $original_item["attach"]; $datarray["app"] = $original_item["app"]; $datarray["plink"] = self::plink($author, $guid); - $datarray["private"] = (($public == "false") ? 1 : 0); + $datarray["private"] = (($public == "false") ? Item::PRIVATE : Item::PUBLIC); $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at; $datarray["object-type"] = $original_item["object-type"]; @@ -2733,7 +2802,7 @@ class Diaspora } /** - * @brief Processes retractions + * Processes retractions * * @param array $importer Array of the importer user * @param array $contact The contact of the item owner @@ -2789,7 +2858,7 @@ class Diaspora continue; } - Item::delete(['id' => $item['id']]); + Item::markForDeletion(['id' => $item['id']]); Logger::log("Deleted target ".$target_guid." (".$item["id"].") from user ".$item["uid"]." parent: ".$item["parent"], Logger::DEBUG); } @@ -2798,7 +2867,7 @@ class Diaspora } /** - * @brief Receives retraction messages + * Receives retraction messages * * @param array $importer Array of the importer user * @param string $sender The sender of the message @@ -2844,7 +2913,7 @@ class Diaspora } /** - * @brief Receives status messages + * Receives status messages * * @param array $importer Array of the importer user * @param SimpleXMLElement $data The message object @@ -2896,7 +2965,7 @@ class Diaspora $datarray["object-type"] = Activity\ObjectType::NOTE; // Add OEmbed and other information to the body - if (!self::isRedmatrix($contact["url"])) { + if (!self::isHubzilla($contact["url"])) { $body = add_page_info_to_body($body, false, true); } } @@ -2922,6 +2991,7 @@ class Diaspora $datarray["guid"] = $guid; $datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid); + $datarray['uri-id'] = ItemURI::insert(['uri' => $datarray['uri'], 'guid' => $datarray['guid']]); $datarray["verb"] = Activity::POST; $datarray["gravity"] = GRAVITY_PARENT; @@ -2931,12 +3001,15 @@ class Diaspora $datarray["body"] = self::replacePeopleGuid($body, $contact["url"]); + self::storeMentions($datarray['uri-id'], $text); + Tag::storeRawTagsFromBody($datarray['uri-id'], $datarray["body"]); + if ($provider_display_name != "") { $datarray["app"] = $provider_display_name; } $datarray["plink"] = self::plink($author, $guid); - $datarray["private"] = (($public == "false") ? 1 : 0); + $datarray["private"] = (($public == "false") ? Item::PRIVATE : Item::PUBLIC); $datarray["changed"] = $datarray["created"] = $datarray["edited"] = $created_at; if (isset($address["address"])) { @@ -2968,7 +3041,7 @@ class Diaspora * ************************************************************************************** */ /** - * @brief returnes the handle of a contact + * returnes the handle of a contact * * @param array $contact contact array * @@ -2994,7 +3067,7 @@ class Diaspora /** - * @brief Creates the data for a private message in the new format + * Creates the data for a private message in the new format * * @param string $msg The message that is to be transmitted * @param array $user The record of the sender @@ -3036,7 +3109,7 @@ class Diaspora } /** - * @brief Creates the envelope for the "fetch" endpoint and for the new format + * Creates the envelope for the "fetch" endpoint and for the new format * * @param string $msg The message that is to be transmitted * @param array $user The record of the sender @@ -3076,7 +3149,7 @@ class Diaspora } /** - * @brief Create the envelope for a message + * Create the envelope for a message * * @param string $msg The message that is to be transmitted * @param array $user The record of the sender @@ -3102,7 +3175,7 @@ class Diaspora } /** - * @brief Creates a signature for a message + * Creates a signature for a message * * @param array $owner the array of the owner of the message * @param array $message The message that is to be signed @@ -3121,7 +3194,7 @@ class Diaspora } /** - * @brief Transmit a message to a target server + * Transmit a message to a target server * * @param array $owner the array of the item owner * @param array $contact Target of the communication @@ -3135,7 +3208,7 @@ class Diaspora */ private static function transmit(array $owner, array $contact, $envelope, $public_batch, $guid = "") { - $enabled = intval(Config::get("system", "diaspora_enabled")); + $enabled = intval(DI::config()->get("system", "diaspora_enabled")); if (!$enabled) { return 200; } @@ -3162,7 +3235,7 @@ class Diaspora Logger::log("transmit: ".$logid."-".$guid." ".$dest_url); - if (!intval(Config::get("system", "diaspora_test"))) { + if (!intval(DI::config()->get("system", "diaspora_test"))) { $content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json"); $postResult = Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]); @@ -3179,7 +3252,7 @@ class Diaspora /** - * @brief Build the post xml + * Build the post xml * * @param string $type The message type * @param array $message The message data @@ -3194,7 +3267,7 @@ class Diaspora } /** - * @brief Builds and transmit messages + * Builds and transmit messages * * @param array $owner the array of the item owner * @param array $contact Target of the communication @@ -3229,7 +3302,7 @@ class Diaspora } /** - * @brief sends a participation (Used to get all further updates) + * sends a participation (Used to get all further updates) * * @param array $contact Target of the communication * @param array $item Item array @@ -3240,7 +3313,7 @@ class Diaspora private static function sendParticipation(array $contact, array $item) { // Don't send notifications for private postings - if ($item['private']) { + if ($item['private'] == Item::PRIVATE) { return; } @@ -3272,13 +3345,13 @@ class Diaspora Logger::log("Send participation for ".$item["guid"]." by ".$author, Logger::DEBUG); // It doesn't matter what we store, we only want to avoid sending repeated notifications for the same item - DI::cache()->set($cachekey, $item["guid"], Cache::QUARTER_HOUR); + DI::cache()->set($cachekey, $item["guid"], Duration::QUARTER_HOUR); return self::buildAndTransmit($owner, $contact, "participation", $message); } /** - * @brief sends an account migration + * sends an account migration * * @param array $owner the array of the item owner * @param array $contact Target of the communication @@ -3290,7 +3363,7 @@ class Diaspora */ public static function sendAccountMigration(array $owner, array $contact, $uid) { - $old_handle = PConfig::get($uid, 'system', 'previous_addr'); + $old_handle = DI::pConfig()->get($uid, 'system', 'previous_addr'); $profile = self::createProfileData($uid); $signed_text = 'AccountMigration:'.$old_handle.':'.$profile['author']; @@ -3306,7 +3379,7 @@ class Diaspora } /** - * @brief Sends a "share" message + * Sends a "share" message * * @param array $owner the array of the item owner * @param array $contact Target of the communication @@ -3350,7 +3423,7 @@ class Diaspora } /** - * @brief sends an "unshare" + * sends an "unshare" * * @param array $owner the array of the item owner * @param array $contact Target of the communication @@ -3371,7 +3444,7 @@ class Diaspora } /** - * @brief Checks a message body if it is a reshare + * Checks a message body if it is a reshare * * @param string $body The message body that is to be check * @param bool $complete Should it be a complete check or a simple check? @@ -3429,7 +3502,7 @@ class Diaspora } /** - * @brief Create an event array + * Create an event array * * @param integer $event_id The id of the event * @@ -3509,7 +3582,7 @@ class Diaspora } /** - * @brief Create a post (status message or reshare) + * Create a post (status message or reshare) * * @param array $item The item that will be exported * @param array $owner the array of the item owner @@ -3531,12 +3604,12 @@ class Diaspora $myaddr = self::myHandle($owner); - $public = ($item["private"] ? "false" : "true"); + $public = ($item["private"] == Item::PRIVATE ? "false" : "true"); $created = DateTimeFormat::utc($item['received'], DateTimeFormat::ATOM); $edited = DateTimeFormat::utc($item["edited"] ?? $item["created"], DateTimeFormat::ATOM); // Detect a share element and do a reshare - if (!$item['private'] && ($ret = self::isReshare($item["body"]))) { + if (($item['private'] != Item::PRIVATE) && ($ret = self::isReshare($item["body"]))) { $message = ["author" => $myaddr, "guid" => $item["guid"], "created_at" => $created, @@ -3551,7 +3624,7 @@ class Diaspora $body = $item["body"]; // Fetch the title from an attached link - if there is one - if (empty($item["title"]) && PConfig::get($owner['uid'], 'system', 'attach_link_title')) { + if (empty($item["title"]) && DI::pConfig()->get($owner['uid'], 'system', 'attach_link_title')) { $page_data = BBCode::getAttachmentData($item['body']); if (!empty($page_data['type']) && !empty($page_data['title']) && ($page_data['type'] == 'link')) { $title = $page_data['title']; @@ -3575,7 +3648,7 @@ class Diaspora if ($item["attach"]) { $cnt = preg_match_all('/href=\"(.*?)\"(.*?)title=\"(.*?)\"/ism', $item["attach"], $matches, PREG_SET_ORDER); if ($cnt) { - $body .= "\n".L10n::t("Attachments:")."\n"; + $body .= "\n".DI::l10n()->t("Attachments:")."\n"; foreach ($matches as $mtch) { $body .= "[".$mtch[3]."](".$mtch[1].")\n"; } @@ -3628,7 +3701,7 @@ class Diaspora $msg = ["type" => $type, "message" => $message]; - DI::cache()->set($cachekey, $msg, Cache::QUARTER_HOUR); + DI::cache()->set($cachekey, $msg, Duration::QUARTER_HOUR); return $msg; } @@ -3648,7 +3721,7 @@ class Diaspora } /** - * @brief Sends a post + * Sends a post * * @param array $item The item that will be exported * @param array $owner the array of the item owner @@ -3667,7 +3740,7 @@ class Diaspora } /** - * @brief Creates a "like" object + * Creates a "like" object * * @param array $item The item that will be exported * @param array $owner the array of the item owner @@ -3699,7 +3772,7 @@ class Diaspora } /** - * @brief Creates an "EventParticipation" object + * Creates an "EventParticipation" object * * @param array $item The item that will be exported * @param array $owner the array of the item owner @@ -3737,7 +3810,7 @@ class Diaspora } /** - * @brief Creates the object for a comment + * Creates the object for a comment * * @param array $item The item that will be exported * @param array $owner the array of the item owner @@ -3774,7 +3847,7 @@ class Diaspora if ( $item['author-id'] != $thread_parent_item['author-id'] && (empty($item['uid']) || !Feature::isEnabled($item['uid'], 'explicit_mentions')) - && !Config::get('system', 'disable_implicit_mentions') + && !DI::config()->get('system', 'disable_implicit_mentions') ) { $body = self::prependParentAuthorMention($body, $thread_parent_item['author-link']); } @@ -3798,13 +3871,13 @@ class Diaspora $comment['thread_parent_guid'] = $thread_parent_item['guid']; } - DI::cache()->set($cachekey, $comment, Cache::QUARTER_HOUR); + DI::cache()->set($cachekey, $comment, Duration::QUARTER_HOUR); return($comment); } /** - * @brief Send a like or a comment + * Send a like or a comment * * @param array $item The item that will be exported * @param array $owner the array of the item owner @@ -3838,7 +3911,7 @@ class Diaspora } /** - * @brief Creates a message from a signature record entry + * Creates a message from a signature record entry * * @param array $item The item that will be exported * @return array The message @@ -3883,7 +3956,7 @@ class Diaspora } /** - * @brief Relays messages (like, comment, retraction) to other servers if we are the thread owner + * Relays messages (like, comment, retraction) to other servers if we are the thread owner * * @param array $item The item that will be exported * @param array $owner the array of the item owner @@ -3905,30 +3978,24 @@ class Diaspora Logger::log("Got relayable data ".$type." for item ".$item["guid"]." (".$item["id"].")", Logger::DEBUG); - // Old way - is used by the internal Friendica functions - /// @todo Change all signatur storing functions to the new format - if ($item['signed_text'] && $item['signature'] && $item['signer']) { - $message = self::messageFromSignature($item); - } else {// New way - $msg = json_decode($item['signed_text'], true); - - $message = []; - if (is_array($msg)) { - foreach ($msg as $field => $data) { - if (!$item["deleted"]) { - if ($field == "diaspora_handle") { - $field = "author"; - } - if ($field == "target_type") { - $field = "parent_type"; - } - } + $msg = json_decode($item['signed_text'], true); - $message[$field] = $data; + $message = []; + if (is_array($msg)) { + foreach ($msg as $field => $data) { + if (!$item["deleted"]) { + if ($field == "diaspora_handle") { + $field = "author"; + } + if ($field == "target_type") { + $field = "parent_type"; + } } - } else { - Logger::log("Signature text for item ".$item["guid"]." (".$item["id"].") couldn't be extracted: ".$item['signed_text'], Logger::DEBUG); + + $message[$field] = $data; } + } else { + Logger::log("Signature text for item ".$item["guid"]." (".$item["id"].") couldn't be extracted: ".$item['signed_text'], Logger::DEBUG); } $message["parent_author_signature"] = self::signature($owner, $message); @@ -3939,7 +4006,7 @@ class Diaspora } /** - * @brief Sends a retraction (deletion) of a message, like or comment + * Sends a retraction (deletion) of a message, like or comment * * @param array $item The item that will be exported * @param array $owner the array of the item owner @@ -3974,7 +4041,7 @@ class Diaspora } /** - * @brief Sends a mail + * Sends a mail * * @param array $item The item that will be exported * @param array $owner The owner @@ -4025,7 +4092,7 @@ class Diaspora } /** - * @brief Split a name into first name and last name + * Split a name into first name and last name * * @param string $name The name * @@ -4081,7 +4148,7 @@ class Diaspora } /** - * @brief Create profile data + * Create profile data * * @param int $uid The user id * @@ -4090,20 +4157,11 @@ class Diaspora */ private static function createProfileData($uid) { - $r = q( - "SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.*, `user`.`prvkey` AS `uprvkey`, `contact`.`addr` - FROM `profile` - INNER JOIN `user` ON `profile`.`uid` = `user`.`uid` - INNER JOIN `contact` ON `profile`.`uid` = `contact`.`uid` - WHERE `user`.`uid` = %d AND `profile`.`is-default` AND `contact`.`self` LIMIT 1", - intval($uid) - ); - - if (!$r) { + $profile = DBA::selectFirst('owner-view', ['uid', 'addr', 'name', 'location', 'net-publish', 'dob', 'about', 'pub_keywords'], ['uid' => $uid]); + if (!DBA::isResult($profile)) { return []; } - $profile = $r[0]; $handle = $profile["addr"]; $split_name = self::splitName($profile['name']); @@ -4113,7 +4171,7 @@ class Diaspora $large = DI::baseUrl().'/photo/custom/300/'.$profile['uid'].'.jpg'; $medium = DI::baseUrl().'/photo/custom/100/'.$profile['uid'].'.jpg'; $small = DI::baseUrl().'/photo/custom/50/' .$profile['uid'].'.jpg'; - $searchable = (($profile['publish'] && $profile['net-publish']) ? 'true' : 'false'); + $searchable = ($profile['net-publish'] ? 'true' : 'false'); $dob = null; $about = null; @@ -4130,10 +4188,9 @@ class Diaspora $dob = DateTimeFormat::utc($year . '-' . $month . '-'. $day, 'Y-m-d'); } - $about = $profile['about']; - $about = strip_tags(BBCode::convert($about)); + $about = BBCode::toMarkdown($profile['about']); - $location = Profile::formatLocation($profile); + $location = $profile['location']; $tags = ''; if ($profile['pub_keywords']) { $kw = str_replace(',', ' ', $profile['pub_keywords']); @@ -4157,7 +4214,6 @@ class Diaspora "image_url_medium" => $medium, "image_url_small" => $small, "birthday" => $dob, - "gender" => $profile['gender'], "bio" => $about, "location" => $location, "searchable" => $searchable, @@ -4166,7 +4222,7 @@ class Diaspora } /** - * @brief Sends profile data + * Sends profile data * * @param int $uid The user id * @param bool $recips optional, default false @@ -4208,7 +4264,7 @@ class Diaspora } /** - * @brief Creates the signature for likes that are created on our system + * Creates the signature for likes that are created on our system * * @param integer $uid The user of that comment * @param array $item Item array @@ -4239,7 +4295,7 @@ class Diaspora } /** - * @brief Creates the signature for Comments that are created on our system + * Creates the signature for Comments that are created on our system * * @param integer $uid The user of that comment * @param array $item Item array